找不到指定的商店

时间:2013-07-31 11:38:26

标签: sencha-touch sencha-touch-2.1

我处于Sencha touch的初级水平。现在,我正在经历这个tutorial。虽然这个教程已经过时了,但直到现在我还是在文档的帮助下设法与Sencha touch的新方法同步。

我的问题是,当我在Chrome中运行代码时,我收到了控制台错误[WARN][Ext.dataview.List#applyStore] The specified Store cannot be found

预期结果是它将显示一个数据列表,该数据列表通过itmTpl config存储。

以下是fiddle

我也尝试通过创建modelstore作为

来解决它
model --> NotesApp.model.Notes       (instead of "Notes")
store --> NotesApp.store.NotesStore  (instead of "NotesStore")

但没用。还是一样的错误。

1 个答案:

答案 0 :(得分:1)

您关注的教程是旧样式,我建议您遵循此tutorial.

相同的应用程序,但你所遵循的不是MVC和我在MVC之后共享的教程,当我开始使用sencha touch时,我遵循了本教程。

这个应用程序对你来说是一个好的开始,另外我想提一下,这个应用程序只是一个不完美的开始。

随着您了解更多,您将了解最佳实践。


话虽如此,让我们解决旧代码中的警告

您刚刚定义了商店,但未在商店管理器中创建和注册NotesStore

Ext.regStore(id,config)会为您完成此操作,请尝试使用此代码。

Ext.application({
    name : ('SF' || 'SenchaFiddle'),
    launch : function() {
       Ext.define('Notes', {
            extend: 'Ext.data.Model',
            id: 'modelId',
            config: {
                fields: [
                    { name: 'id', type: 'int' },
                    { name: 'date', type: 'date', dateFormat: 'c' },
                    { name: 'title', type: 'string' },
                    { name: 'narrative', type: 'string' }
                ],
                validations: [
                    { type: 'presence', field: 'id' },
                    { type: 'presence', field: 'title' }
                ]
            }
        });

      Ext.regStore('NotesStore', {
            require: 'Ext.data.Store',
            model: 'Notes',
            storeId : 'NotesStore',
            sorters: [{
                property: 'date',
                direction: 'DESC'
            }],
            proxy: {
                type: 'localstorage',
                id: 'notes-app-store'
            },
            // TODO: remove this data after testing.
            data: [
                { id: 1, date: new Date(), title: 'Test Note', narrative: 'This is simply a test note' }
            ]
        });


        Ext.Viewport.add({
            xtype: 'panel',
            fullscreen: true,
            layout: 'card',
            html: "hello",
            items: [{
                xtype: 'panel',
                id: 'notesListContainer',
                layout: 'fit',
                html: 'This is the notes list container',
                items: [{
                    xtype: 'toolbar',
                    docked: 'top',
                    id: 'notesListToolbar',
                    title: 'My Notes'
                },
                {
                    xtype: 'list',
                    id: 'notesList',
                    //require: ['Notes.model.Notes','NotesApp.store.NotesStore'],
                    store: 'NotesStore',
                    itemTpl: '<div class="list-item-title">{title}</div>' +
                            '<div class="list-item-narrative">{narrative}</div>'
                }]
            }]
        });
    }
});
相关问题