【问题标题】:getStore(); undefined Sencha Touch 2获取商店(); undefined Sencha Touch 2
【发布时间】:2014-01-25 02:11:46
【问题描述】:

我有 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,但这应该不是问题。

【问题讨论】:

  • 你能设置一个jsfiddle吗?
  • 愚蠢的问题...但是您确定第二个商店已加载并实例化吗?
  • 我使用 Architect 创建商店,我可以看到它已满载记录。我不确定它是否已实例化,但据我所知,我以前从未这样做过..或者我可能在不知情的情况下做到了。
  • 您是从“第二组”中删除“s”还是打错字??
  • 是的,我也注意到了,我将其更改为所有(商店、模型和 storeId)现在都具有相同的名称(第二组),但它仍然让我未定义..

标签: extjs store


【解决方案1】:

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

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

【讨论】:

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