getStore(); undefined Sencha Touch 2

4

I have 2 stores with loaded data.

First store:

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'
我似乎找不到问题所在。您有任何建议应该朝哪个方向寻找问题吗?
注:我正在使用Sencha Architect,但这不应该成为问题。

你能设置一个 jsfiddle 吗? - martskins
愚蠢的问题...但你确定第二个存储已经被加载和实例化了吗? - arthurakay
我使用Architect创建了存储,我可以看到它已经完全加载了记录。我不确定它是否被实例化,但据我所知,我以前从未这样做过...或者可能是我在不知情的情况下这样做了。 - Prometheus
你是不是把“Secondgroup”中的“s”掉了,还是打错字了? - lmno
是的,我也注意到了,我把所有的名称(store、model和storeId)都改成了相同的名称(Secondgroups),但它仍然显示未定义。 - Prometheus
你是否将 store 添加到 Ext.application 中了?例如:Ext.application({ name: 'MyApp', models: ['model1', 'model2'], stores: ['Groups', 'Secondgroup'] }); - Jimmy
1个回答

4

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

对于第二组,请尝试使用Ext.getStore('Secondgroups');这样应该对您有用。


我找到了解决方案!我定义了存储,但不知何故它还没有被创建,而我的第一个存储已经存在。我需要做的唯一一件事是:Ext.create('Connecting.store.Secondgroups', { }); 然后我使用了 var store = Ext.getStore('Secondgroups');之后,“未定义”的问题就消失了,我可以填充我的存储器 :) - Prometheus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接