2014-01-07 163 views
4

我有2个加载数据的商店。getStore(); undefined Sencha Touch 2

第一店:

Ext.define('Connecting.store.Groups', { 
    extend: 'Ext.data.Store', 

    requires: [ 
     'Connecting.model.groupModel', 
     'Ext.data.proxy.Ajax', 
     'Ext.data.reader.Json' 
    ], 

    config: { 
     autoLoad: true, 
     model: 'Connecting.model.groupModel', 
     storeId: 'Groups', 
     proxy: { 
      type: 'ajax', 
      url: 'http://localhost/php/getGroups.php', 
      reader: { 

        type: 'json' 
       } 
      } 
     } 
    }); 

二店:

Ext.define('Connecting.store.Secondgroups', { 
    extend: 'Ext.data.Store', 

    requires: [ 
     'Connecting.model.Secondgroup', 
     'Ext.data.proxy.Ajax', 
     'Ext.data.reader.Json' 
    ], 

    config: { 
     autoLoad: true, 
     model: 'Connecting.model.Secondgroup', 
     storeId: 'Secondgroup', 
     proxy: { 
      type: 'ajax', 
      url: 'http://localhost/php/getSecondGroup.php', 
      reader: { 
       type: 'json' 
      } 
     } 
    } 
}); 

第一家店工程;

var store = Ext.getStore('Groups'); 
console.log(store); 

但是,当我改变storeId为“Secondgroup”(在getStore)我console.log会给我一个'undefined' ..

似乎不是我可以在发现问题..在什么方向有什么建议我必须看看?

PS。我正在使用Sencha Architect,但这不应该是一个问题。

+0

你能设置一个jsfiddle吗? – lascort

+0

愚蠢的问题......但你确定第二家商店加载和实例化? – arthurakay

+0

我使用Architect来创建商店,并且我可以看到它完全加载了记录。我不确定它的实例化,但据我所知,我从来没有这样做过,或者我不知道它做到了。 –

回答

4

Sencha Touch实际上使用了您在定义中使用的内容。

对于第二组,尝试使用Ext.getStore('Secondgroups');这应该适合你。

+0

我找到了解决方案!我定义了这家商店,但不知何故,当我第一家店时,它还没有创建。我唯一需要做的是:Ext.create('Connecting.store.Secondgroups',{ });然后我用var store = Ext.getStore('Secondgroups'); 之后,'undefined'消失了,我可以填满我的店:) –