extJs - 使用字符串数组填充网格面板

时间:2014-03-23 20:06:29

标签: json extjs extjs4 gridpanel

我从服务器收到一串字符串。 如果数据不是键值格式,我如何填充网格面板?

以下是回复:

{"result":true,"data":["dep1","dep2","dep3"],"totalCount":3}

这是我的网格面板

xtype: 'gridpanel',
flex: 1,
itemId: 'departmentsGridPanel',
title: '',
store: new Ext.data.ArrayStore({
    autoLoad: true,
    fields: [
        'department'
    ],
    proxy: {
        type: 'ajax',
        url: 'FilteringDataServlet?filterColumn=avdeling',
        reader: {
            type: 'json',
            root: 'data'
        }
    }
}),
columns: [{
    text: 'Avdeling',
    flex: 1,
    dataIndex: 'department'
}],

2 个答案:

答案 0 :(得分:1)

然后,您应该将Ext.data.reader.Arraymapping参数一起使用。

Employee = Ext.define('Employee', {
extend: 'Ext.data.Model',
fields: [
    {name: 'name', mapping: 0},         // "mapping" only needed if an "id" field is present which
    {name: 'occupation', mapping: 1}    // precludes using the ordinal position as the index.        
]
});

答案 1 :(得分:0)

我通过向我的商店添加load监听器并修改那里的数据来解决这个问题

listeners: { 
  load: function(store, records, success, opts) { 
           store.each(function(record) { 
              record.set('department', record.raw); 
           }); 
         } 
}