English 中文(简体)
可否宣布Ext.Component为全球变量?
原标题:Is it possible to declare Ext.Component as global variables?

我在优化我的Sencha Touch 2口供时多次面对这一问题。

It s obvious that I should keep the DOM light-weighted, my application contains an Ext.TabBar and a main Ext.Container above. Everytime when switch from a view to another, I simply remove current view and add new view to that Container.

但是,问题在于,有一些观点已经cus化数据。 我指的是他们有内部数据,如html的内容、过滤的储存记录等。 当我把他们从我的主要集装箱中搬走时,我想将他们的“状态”拯救到全球变量,例如: Im与产品进行电子交换,并附上细节。 在从主要集装箱中删除详细小组时,我想做这样的事情:

var saved_detail_panel = mainContainer.getActiveItem();

如果我能够这样做,那么,在我想把这个细节重新添加到主要集装箱时,我只能使用:

mainContainer.add(saved_detail_panel);

I ve tried many times but could not find one that works yet.

非常感谢任何帮助。 谢谢。

Updated: When I put this code in my event handler in a controller:

var temp = Ext.create( taxi.view.location.LocationPanel , {showAnimation: null});
taxi.main_container = temp;

它运作良好,但不是干.。 我想要做的是,在我的<>申请.js上只创造一席之地。

launch: function(){
var temp = Ext.create( taxi.view.location.LocationPanel , {showAnimation: null});
};

and only use this in Controller:

taxi.main_container = temp;

它第一次运作。 但第二次出现这一错误:

Uncaught TypeError: Cannot call method  replaceCls  of null 
最佳回答

你们能否使用“全球名称空间”的标识? 然后,你可以参考MyApp.saved。 贵方的价值观如何?

Ext.application({
    name:  MyApp ,

//    views: [],
//    models: [],
//    stores: [],
    controllers: [ Main ],

    launch: function() {
        MyApp.savedValue = "Hello word";
        Ext.Viewport.add(Ext.create( Sencha.view.tablet.MainView ));
    }
});

“Sencha”实例中的另一个想法是“SchenSink demo”。 ,他们使用一种观点,在座标:{}上设立,通过一个接机/台取。 我认为,主要控制者总是坚持下去,以便永远能够找到你的切身。 事实上,如果你们的所有控制者重新装上 app子,他们是否坚持了吗?

 controllers: [ Main , FooController ,  BarController ],

Snippets from: app/ Controllers/Main.js

config: {
        /**
         * @private
         */
        viewCache: [], // Accessed via getViewCache(), setViewCache()

        ...
},

 createView: function(name) {
        var cache = this.getViewCache(), // Implied getter
            ln = cache.length,
            limit = 20, // max views to cache
            view, i, oldView;

       // See if view is already in the cache and return it
        Ext.each(cache, function(item) {
            if (item.viewName === name) {
                view = item;
                return;
            }
        }, this);

        if (view) {
            return view;
        }

        // If we ve reached our cache limit then remove something

        if (ln >= limit) {
            for (i = 0; i < ln; i++) {
                oldView = cache[i];
                if (!oldView.isPainted()) {
                    oldView.destroy();
                    cache.splice(i, 1);
                    break;
                }
            }
        }
        // Create the view and add it to the cache
        view = Ext.create(name);
        view.viewName = name;
        cache.push(view);
        this.setViewCache(cache); // Implied setter

        return view;
    },  
问题回答

审判

var appNS = new Ext.application({

    name:  app ,
    //others

    launch: function () {    
        appNS.SavedValue =  getting start.......... ;       
    },

    //others

});

之后,你可以在控制器内使用。

console.log(appNs.SavedValue);

i 希望这样做可能是有益的。

another soln is caching ur views. it is not actually caching. first add an array to your application like .

Ext.application({
name:  app ,


viewCache: [],

viewCacheCount: 0,


launch: function () {     

    this.viewCache.push("app init......."); // push your view

}
});

并且可以在任何象控制器这样的控制器内回收

ths.getApplication().viewCache.pop();      //pop your view

我知道,如果某些看法/内容可以自动销毁,可能会造成一些问题。

Try to add autoDestroy: false in your view.

Ext.define( JiaoJiao.view.personal.Card , {

 extend:  Ext.NavigationView ,
 xtype:  personalContainer ,

 config: {

     tab: {
         title:  个人 ,
         iconCls:  user ,
         action:  personalTab 
     },

     autoDestroy: false,

     items: [
         {
             xtype: personal ,
             store:  Personals 
         }
     ]
 }
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签