【问题标题】:Sencha Touch DataView not showing items from StoreSencha Touch DataView 不显示商店中的项目
【发布时间】:2012-02-04 07:36:18
【问题描述】:

我正在使用 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"
    }
});

看了Data view in Sencha touch之后,我添加了autoLoad和itemSelector,还是不行。

虽然跑步

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

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

更新

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

  • 存储对象
  • json 存储符号,如第一个示例 here
  • 可以使用StoreManager.lookup解析的已创建商店的名称

所以我最终得到:

  1. store:'Dataset' 留在视图中
  2. storeId : "Dataset"添加到store,这样可以通过StoreManager解决
  3. 添加导致创建majestic.store.Datasetstores: ['Dataset'] 并将其注册到StoreManager 中

P.S. 也可以在 GridView 的 initialization 方法中使用 this.setStore(new majestic.store.Dataset()) 来完成,但我更喜欢可能的声明方式

【问题讨论】:

    标签: store dataview sencha-touch-2


    【解决方案1】:

    以下是一些建议:

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

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

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

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

    【讨论】:

      【解决方案2】:

      也许你缺少一个 id 字段

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-29
        • 1970-01-01
        • 2012-06-17
        • 2013-04-08
        • 2011-09-01
        • 2014-03-03
        • 2014-01-25
        • 2015-12-28
        相关资源
        最近更新 更多