【问题标题】:Loading data into List using store sencha touch 2使用 store sencha touch 2 将数据加载到 List
【发布时间】:2012-03-31 19:24:12
【问题描述】:

我使用 Sencha touch 2 创建了导航视图。导航视图具有列表组件,我想使用商店和模型加载它。我根据需要创建了模型和存储。在运行我的应用程序时,列表不会呈现任何数据。 它还在 conolse [Ext.dataview.List#applyStore] The specified Store cannot be found 中给出警告。我不确定这个错误是什么意思。 这是我的 mvc 代码,

型号:

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

}
});

谁能指出我缺少什么/ 任何帮助表示赞赏。

【问题讨论】:

    标签: extjs sencha-touch-2


    【解决方案1】:

    列表的items 中的store 属性必须是实例,而不是类的名称。 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
             }]
    
        }
    });
    

    【讨论】:

    • Ext.create 将创建我的商店的新实例。如果我想在任何地方都使用我的同一个商店,那么我必须将它添加到我缺少的 app.js stores:['blogs']。另外store:'GS.store.blogs'我改成了'store:'blogs'',现在可以正常工作了。
    • 此警告 [Ext.dataview.List#applyStore] The specified Store cannot be found 已通过在博客商店中添加 requires:['GS.model.BlogModel'] 得到解决。
    • 我创建了一次商店实例,然后使用Ext.data.StoreManager.lookup 在任何地方使用同一个商店。很高兴知道你的方法也有效;我学到了一些新东西:)
    猜你喜欢
    • 1970-01-01
    • 2012-08-18
    • 2013-07-04
    • 1970-01-01
    • 2012-12-22
    • 2014-02-06
    • 2013-08-21
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多