2012-03-31 127 views
4

我已经使用Sencha touch 2创建了navigaton视图。导航视图具有我希望使用商店和模型加载它的列表组件。我根据需要创建了模型和商店。在运行我的应用程序时,列表不会显示任何数据。 它还通过[Ext.dataview.List#applyStore] The specified Store cannot be found发出警告。我不确定这个错误的含义。 这里是我的MVC代码,使用商店sencha touch将数据加载到列表中2

型号:

Ext.define('GS.model.BlogModel', { 
extend: 'Ext.data.Model', 

config: { 
    fields: [ 
     {name: 'title', type: 'auto'}, 
     {name: 'author', type: 'auto'}, 
     {name: 'content', type:'auto'} 
     ] 
    } 
}); 

店:

Ext.define('GS.store.blogs',{ 
extend:'Ext.data.Store', 
config:{ 
    model:'GS.model.BlogModel', 
    autoLoad :true, 
    proxy:{ 
       type:'jsonp', 
       url:'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog', 
       reader:{ 
        type:'json', 
        rootProperty:'responseData.feed.entries' 
       } 
      } 
} 
}); 

观点:

Ext.define('GS.view.Blog',{ 
extend:'Ext.navigation.View', 
xtype:'blog', 
requires:[ 
    'Ext.dataview.List', 
    'Ext.data.proxy.JsonP', 
    'Ext.data.Store', 
    'GS.store.blogs' 
], 
config: { 
    title:'Blog', 
    iconCls:'star', 
    items:{ 
     xtype:'list', 
     itemTpl:'{title}', 
     title:'Recent Posts', 
     store:'GS.store.blogs' 
    } 

} 
}); 

有人能指出我什么是缺少/ 任何帮助赞赏。

回答

5

storeitems属性为您的列表需要是一个实例,而不是类的名称。 GS.store.blogs是类名。您需要使用Ext.create创建此类的实例,并在items中传递该实例。哦,是的,你的语法items也是错误的。需要是一个数组[]不是对象{}。所以像这样:

var blogsStore = Ext.create("GS.store.blogs"); //put this in the items list 

Ext.define('GS.view.Blog',{ 
    extend:'Ext.navigation.View', 
    xtype:'blog', 
    requires:[ 
     'Ext.dataview.List', 
     'Ext.data.proxy.JsonP', 
     'Ext.data.Store', 
     'GS.store.blogs' 
    ], 
    config: { 
     title:'Blog', 
     iconCls:'star', 
     items:[{ 
      xtype:'list', 
      itemTpl:'{title}', 
      title:'Recent Posts', 
      store: blogsStore //Store instance here. And items are in array, not Object 
     }] 

    } 
}); 
+0

Ext.create将创建我的商店的新实例。如果我想在每个地方使用同一家商店,那么我必须将其添加到我缺少的app.js'stores:['blogs']'中。此外'商店:'GS.store.blogs''我改为'商店:'博客''现在工作正常。 – mehul9595 2012-04-01 08:33:41

+0

此警告'[Ext.dataview.List#applyStore]无法找到指定的商店“已通过在博客商店中添加需要:['GS.model.BlogModel']'解决。 – mehul9595 2012-04-01 08:37:22

+0

我创建了商店实例一次,然后使用'Ext.data.StoreManager.lookup'在任何地方使用同一家商店。很高兴知道你的方式也行得通;我学到了新的东西:) – Jay 2012-04-01 09:42:19

相关问题