4

我正在使用 Sencha touch 2。我已经存储了来自现有 js 对象的负载:

Ext.define('majestic.store.Dataset', {
    extend : 'Ext.data.Store',

    requires : [
        'majestic.model.Dataset',
        'majestic.util.config.ConfigurationManager'
    ],
    config : {
        model   : 'majestic.model.Dataset',
        type: 'memory',
        reader: 'json',
        autoLoad : true,
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                rootProperty : 'datasets'
            }
        }

    },
    constructor: function(config) {
        this.callParent(arguments);
        this.applyData(majestic.util.config.ConfigurationManager.getConfig());
    }

});

模型:

Ext.define('majestic.model.Dataset', {
    extend : 'Ext.data.Model',

    config : {
        fields : [
            'title'
        ],

        associations: [
              {type: 'hasMany', model: 'Layer', name: 'layers'}
        ]

    }
});

并查看:

Ext.define('majestic.view.LayerList', {
    requires: ['majestic.store.Dataset'],
    extend: 'Ext.dataview.List',
    config:{
        store: 'Dataset',
        itemTpl: '<div>{id} is {title}</div>',
        itemSelector: "div"
    }
});

在 Sencha touch 中查看数据视图后,我添加了 autoLoad 和 itemSelector,但仍然没有运气。

虽然跑

new majestic.store.Dataset().each(function(i) {console.log(i)}); 

输出具有填充数据属性的对象列表。

更新

我同意@fbrandel 的第一个选项是它应该如何工作,但是在阅读 ST 源之后,我发现 dataview 的 store 参数被解释为:

所以我最终得到:

  1. 离开store:'Dataset'视野
  2. 添加storeId : "Dataset"到商店,所以它可以由 StoreManager 解决
  3. 添加stores: ['Dataset']导致创建majestic.store.Dataset并在 StoreManager 中注册的内容

PS它也可以使用GridViewthis.setStore(new majestic.store.Dataset())initialization方法来完成,但我更喜欢可能的声明方式

4

2 回答 2

2

以下是一些建议:

  1. 尝试将商店设置为“majestic.store.Dataset”而不仅仅是数据集
  2. 像这样将商店依赖项添加到您的 app.js 中:

    Ext.application({
        name: 'majestic',
        stores: ['Dataset'],
    
        launch: function() {   
           ...
        }
    });
    
  3. 不要将字符串传递给 store 属性,而是传递一个实例:

    store: Ext.create('majestic.store.Dataset')
    

选项#1 似乎是它应该如何工作的最明显的方式。如果没有,这可能是 ST2 中的错误。

于 2012-02-04T21:57:17.793 回答
0

也许你缺少一个 id 字段

无论如何,我在 Architect 中也没有运气,但似乎是一个完全不同的问题。我将按照 Architect 中的教程(构建您的第一个移动应用程序)进行操作,也许会有所了解。

于 2012-06-12T06:45:44.120 回答