【问题标题】:Sencha Touch 2: 'specified Store cannot be found'Sencha Touch 2:“找不到指定的商店”
【发布时间】:2013-02-15 18:22:01
【问题描述】:

我正在尝试将 JSON 数据加载到 NestedList 中。我在 /app/store/Exhibits.js 中有以下商店文件

Ext.define('VisitTCMIndy.store.Exhibits',{
requires: ['VisitTCMIndy.model.Exhibit', 'Ext.data.proxy.JsonP'],
extend: 'Ext.data.TreeStore',
config: {
    model: 'VisitTCMIndy.model.Exhibit',
    proxy: {
        type: 'jsonp',
        url: 'http://www.example.com/explore.php',
        reader: {
            type: 'json',
            rootPropery: 'children'
        }
    }   
}
});

然后我在/app/view/Explore.js的下面视图中引用它

Ext.define('VisitTCMIndy.view.Explore', {
extend: 'Ext.Container',
requires: [
    'Ext.data.TreeStore',
    'Ext.dataview.NestedList',
    'VisitTCMIndy.store.Exhibits',
],
xtype: 'explorecard',
config: {
    iconCls: 'compass1',
    title: 'Explore',
    layout: 'fit',
    items: [
        {
            xtype: 'titlebar',
            docked: 'top',
            title: 'Explore'
        },
        {
            xtype: 'nestedlist',
            fullscreen: true,
            store: 'VisitTCMIndy.store.Exhibits',
            detailCard: {
                html: 'Explore Details'
            },
            listeners: {
                leafitemtap: function(nestedList, list, index, target, record){
                    var detailCard = nestedList.getDetailCard();
                    detailCard.setHtml('Exhibit Title: '+ record.get('title'));
                }
            }
        }

    ]
}
});

当我转到该页面时,我收到以下警告和一个空列表:

[WARN][Ext.dataview.NestedList#applyStore] 找不到指定的Store

在我的一生中,我无法弄清楚我做错了什么。

【问题讨论】:

    标签: sencha-touch-2 nested-lists


    【解决方案1】:

    好的。原来我必须在我的 app.js 文件中声明我的商店和模型。然后仅通过名称来引用我的商店,而无需其他类定义。因此,我在 app.js 文件中添加了以下内容:

    models: ['Exhibit'],
    stores: ['Exhibits'],
    

    然后,这是我更新后的 Explore.js 视图文件。

    Ext.define('VisitTCMIndy.view.Explore', {
    extend: 'Ext.Container',
    requires: [
        'Ext.data.TreeStore',
        'Ext.dataview.NestedList',
        'VisitTCMIndy.store.Exhibits',
    ],
    xtype: 'explorecard',
    config: {
        iconCls: 'compass1',
        title: 'Explore',
        layout: 'vbox',
        items: [
            {
                xtype: 'titlebar',
                docked: 'top',
                title: 'Explore'
            },
            {
                xtype: 'nestedlist',
                store: 'Exhibits',
                title: 'Museum Levels',
                displayField: 'title',
                detailCard: {
                    html: 'Explore Details'
                },
                listeners: {
                    leafitemtap: function(nestedList, list, index, target, record){
                        var detailCard = nestedList.getDetailCard();
                        detailCard.setHtml('<div style="text-align:center;margin:.5em;"><img src="'+record.get('image')+'" alt="'+record.get('title')+'" />'+
                            '<p style="text-align:left;">'+record.get('text')+'</p></div>'
                        );
                    }
                },
                flex: 1
            }
    
        ]
    }
    });
    

    另外,请注意我将布局从 fit 更改为 vbox。我必须这样做,并将列表的 flex 设置为 1,以便列表现在实际显示它正在加载数据。

    【讨论】: