2014-12-08 67 views
0

我正在经历一个sencha教程,并且在尝试在我的应用中实现商店时收到此错误。我确信这是简单的,我忽略了,但我很难搞清楚它是什么。applyStore]无法找到指定的商店

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' } 
     ] 
    } 
}); 

回答

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' 
    } 
}); 

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

快乐编码!

+0

我想我会先通过几个教程,然后再尝试从头开始创建模型/商店应用程序。感谢您的回复! – 2014-12-08 15:44:52

+0

这很棒。在模型和商店上清除您的想法的最佳位置是:http://docs.sencha.com/touch/2.3.1/#!/guide/models和http://docs.sencha.com/touch/2.3。 1 /#!/引导/店 – 2014-12-09 05:00:23