Sencha - store.each() - 数据不可用,它们只在数据类中很深

jir*_*_cs 2 extjs

我有:

Ext.define("catcher.view.Login", {
   extend: "Ext.form.Panel",
// creating login form, including selectfield
Run Code Online (Sandbox Code Playgroud)

商店"锦标赛"在商店中创建(autoload:true),有其模型.一切都准备好了.需要动态填充selectfield(仍在view.Login类中):

initialize: function(){
        var store = Ext.getStore("Tournaments");        
        var options = new Array();
        store.each(function(radek){
            options[radek.get("tournament_id")] = radek.get("tournament_name");
        });
    }
Run Code Online (Sandbox Code Playgroud)

我不想使用store:"Tournaments"配置选项,因为后来的form.submit(); 不发送正确的数据selectfield.

有问题: console.log(store.getCount());返回0.使用store.add({ ... })我可以添加任何东西,getCount()返回corrent count(0 + add()).

奇怪的部分:console.log(store)返回整个类,包括data所有项目内的对象.接下来奇怪的部分 - 如果我在控制器中使用相同的代码,一切正常,Store正确加载,我可以使用mystore.each();

Eva*_*oli 5

存储加载是异步的,当您访问它时,它不会被加载.您需要侦听商店加载事件.

就像是:

store.on('load', function(storeRef, records, successful){
    //Loop through records
}, this);
Run Code Online (Sandbox Code Playgroud)

on()文档

加载事件文档