List中的itemTpl未显示值

时间:2014-07-18 10:42:18

标签: extjs4.2 sencha-touch-2.1

使用Sencha Touch 2.3

型号:

Ext.define("MyModel", {
    extend: "Ext.data.Model",

    fields: [
        {name: 'id'},
        {name: 'test', type: 'string'},
    ]   
});  

商店:

Ext.define('MyStore', {
    extend: 'Ext.data.Store',
    model: 'MyModel',
    autoLoad: true,

    proxy: {
      type: 'ajax',
      url: 'd.php',
      reader: {
        type: 'json',
        rootProperty: 'data',
        totalProperty : 'totalNumber',
        idProperty: 'id'
      }
    },
});  

列表:

                                {
                                    itemId: 'histTab',
                                    iconCls: 'favorites',
                                    xtype: 'list',
                                    flex:1,
                                    itemTpl: ['{id} / {test}'],
                                    store: mystore
                                },  

数据:

[{
    "success": true,
    "data": \[
        { "id": "1", "test": "test 1" },
        { "id": "2", "test": "test 2"},
        { "id": "3", "test": "test 3" }
    \]
}]  

输出:

output

为什么test字段未显示?

1 个答案:

答案 0 :(得分:1)

试试这个......

的MyStore -

Ext.define('test.store.MyStore', {
extend: 'Ext.data.Store',
model: 'test.model.MyModel',
autoLoad: true,

proxy: {
  type: 'ajax',
  url: 'data.json',
  id: 'MyStore',
  storeId:'MyStore',
  reader: {
    type: 'json',
    rootProperty: 'data',
    totalProperty : 'totalNumber',
    idProperty: 'id'
  }
},

});

列表 -

{
            itemId : 'histTab',
            iconCls : 'favorites',
            xtype : 'list',
            height: 200,
            flex : 1,
            itemTpl : ['{id} / {test}'],
            store : 'MyStore'
}

JSON -

{
"success":true,
"data": [
    { "id": "1", "test": "test 1" },
    { "id": "2", "test": "test 2"},
    { "id": "3", "test": "test 3" }
]

}