简体   繁体   English

ExtJS的。 在渲染上加载商店

[英]ExtJS. Load a store on render

Since this thread seems to be terribly outdated, let me ask a similar question. 由于这个线程似乎非常过时,让我问一个类似的问题。 So, I have a store defined like so: 所以,我有一个如此定义的store

Ext.define('GeoServer.store.ObjectsStore', {
    extend: 'Ext.data.TreeStore',
    requires: ['GeoServer.model.ObjectsModel'],
    model: 'GeoServer.model.ObjectsModel',
    autoLoad: false,
    proxy: {
        type: 'ajax',
        url: 'controller/MapsHandler.php',
        extraParams: {
            action: 'listObjects'
        }
    }
});

As you can see, it has autoLoad set to false . 如您所见,它将autoLoad设置为false This is because I do not want to load dozens of stores on page load, I only want to load them, when I need it. 这是因为我不想在页面加载时加载几十个商店,我只想在需要时加载它们。 For example, in this case I need to load this store, when I show a window with a treepanel inside. 例如,在这种情况下,当我显示一个里面有treepanel的窗口时,我需要加载这个商店。 The way I show this window is: 我展示这个窗口的方式是:

Ext.create("Ext.window.Window",{ 
    title: "Objects",
    height: size.height,
    width: size.width,
    constrainHeader:true,
    layout:"fit",
    maximizable:true,
    items:[{
        xtype: 'treepanel',
        rootVisible: false,
        scrollable: true,
        itemId: 'Objects',
        store: 'ObjectsStore',
        border: false,
        autoLoad: true // has no effect
    }]
}).show();

But the nasty thing is that when the window shows up for the first time, the tree does not get populated with data, even though I see that server request is triggered. 但令人讨厌的是,当窗口第一次显示时,即使我看到服务器请求被触发,树也不会填充数据。 However, when the windows shows up for the second, third, etc. time, everything is ok. 但是,当窗口显示第二,第三等时间时,一切都很好。 So, what is so special with the first time and how to use this autoLoad property in the right way? 那么,第一次有什么特别之处以及如何以正确的方式使用这个autoLoad属性?

You need autoload true on a store if you want the store to load on application start. 如果您希望在应用程序启动时加载商店,则需要在商店中自动加载true。

You have two opportunities, show window on store load: 你有两个机会,在商店负载上显示窗口:

    var store=Ext.getStore('ObjectsStore'),
         view=this.getView();
     view.mask('loading');
     store.on('load',function(){
         view.unmask();
         YourWindow.show();
     });
     store.load();

Or you can try to load the store on before render listeners: 或者您可以尝试在渲染侦听器之前加载存储:

listeners:{
   beforerender: function(){
      Ext.getStore('ObjectsStore').load();
   }
}

In my opinion best solution is the first, Store do an async load, so you'll always see your tree panel populated on his load 在我看来,最好的解决方案是第一个,Store执行异步加载,所以你总是会看到你的树形面板填充在他的负载上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM