2012-03-31 125 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

相關問題