applyStore]找不到指定的商店

时间:2014-12-08 03:10:56

标签: mobile web sencha-touch

我正在阅读一个sencha教程,并且在尝试在我的应用中实现商店时收到此错误。我确信这是一个简单的东西,我忽视了,但我很难搞清楚它是什么。

applyStore]无法找到指定的商店

以下是相关代码:

//from app.js

stores: [
  'MyStore'   
],


//from the view
Ext.define('listerApp2.view.Main', {
    extend: 'Ext.dataview.List',
    xtype: 'main',
    requires: [
        'Ext.TitleBar',
        'listerApp2.store.MyStore'
    ],
    config: {
        title: 'My listing',
        store: 'MyStore'   
    }
});

//from the store
Ext.define('listerApp2.store.MyStore', {
    requires: ['listerApp2.model.MyModel'],

    config: {
        autoload: true,
        model: 'MyModel',
        storeId: 'MyStore',
        alias: 'store.MyStore',
        data: [
            {firstName: 'Washington', lastName: 'George', age: 250},
            {firstName: 'Lincoln', lastName: 'Abe', age: 200},
            {firstName: 'Clinton', lastName: 'Bill', age: 60}            
        ],
        proxy: {
            type: 'localStorage'
        }
    }

});
//and the model
Ext.define('listerApp2.model.MyModel', {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            { name: 'firstName', type: 'string' },
            { name: 'lastName', type: 'string' },
            { name: 'age', type: 'int' }
        ]
    }
});

//from app.js stores: [ 'MyStore' ], //from the view Ext.define('listerApp2.view.Main', { extend: 'Ext.dataview.List', xtype: 'main', requires: [ 'Ext.TitleBar', 'listerApp2.store.MyStore' ], config: { title: 'My listing', store: 'MyStore' } }); //from the store Ext.define('listerApp2.store.MyStore', { requires: ['listerApp2.model.MyModel'], config: { autoload: true, model: 'MyModel', storeId: 'MyStore', alias: 'store.MyStore', data: [ {firstName: 'Washington', lastName: 'George', age: 250}, {firstName: 'Lincoln', lastName: 'Abe', age: 200}, {firstName: 'Clinton', lastName: 'Bill', age: 60} ], proxy: { type: 'localStorage' } } }); //and the model Ext.define('listerApp2.model.MyModel', { extend: 'Ext.data.Model', config: { fields: [ { name: 'firstName', type: 'string' }, { name: 'lastName', type: 'string' }, { name: 'age', type: 'int' } ] } });

1 个答案:

答案 0 :(得分:0)

您在代码中混淆了很多东西。对于例如您使用的localStoragestoreId在这里没有任何意义。我已经简化了你的代码并粘贴在这里:

<强>模型

Ext.define('MyApp.model.DataModel', {
extend: 'Ext.data.Model',

     config: {
        fields: [
            { name: 'firstName', type: 'string' },
            { name: 'lastName', type: 'string' },
            { name: 'age', type: 'int' }
        ]
    }
});

商品

Ext.define('MyApp.store.DataStore', {
 extend: 'Ext.data.Store',
    config: {
      model: 'MyApp.model.DataModel',
      autoLoad: true,

      data: [
            {firstName: 'Washington', lastName: 'George', age: 250},
            {firstName: 'Lincoln', lastName: 'Abe', age: 200},
            {firstName: 'Clinton', lastName: 'Bill', age: 60}            
        ]
  }
}); 

查看

Ext.define('MyApp.view.HobbyList', {
    extend: 'Ext.List',
    xtype: 'hobbyList',
    requires: [
    'Ext.dataview.List'
    ],
    config: {
        styleHtmlContent : true, 
        itemTpl : new Ext.XTemplate(
            '{firstName} {lastName} is {age} years old.'
            ),
        store: 'DataStore'
    }
}); 

我测试了这个。它工作正常。看一看。

快乐的编码!