Loading data into List using store sencha touch 2

允我心安 提交于 2019-12-18 17:11:36

问题


I have created navigaton view using Sencha touch 2. Navigation view has list component which i want to load it using store and model. I created model and store as required. On running my app the list does not render any data. It also gives warning in conolse [Ext.dataview.List#applyStore] The specified Store cannot be found . I am not sure what this error means. Here is my mvc code,

model:

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

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

store:

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

view:

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

}
});

Can someone point me out what is missing/ Any help appreciated.


回答1:


The store property in items for your list needs to be an instance, not the name of the class. GS.store.blogs is the class name. You need to create an instance of this class using Ext.create and pass that instance in items. Oh yeah, and your syntax for items is wrong too. Needs to be an array [] not an object {}. So something like:

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
         }]

    }
});


来源:https://stackoverflow.com/questions/9958949/loading-data-into-list-using-store-sencha-touch-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!