[英]ExtJS 4.2 - How to map array to a model field and display dynamically on a grid column?
我有這個json數據:
{ id: 1, name: 'something', description: 'somethingsomething', customers: [{ id: 1, username: 'cust1' }, { id: 2, username: 'cust2' }] }
雖然我在網格面板上顯示前三個字段沒有問題,但是我在檢索customers
字段的數組對象時遇到了問題。 我的模型是這樣的:
fields: [ 'id', { name: 'name', sortType: Ext.data.SortTypes.asUCString }, 'permanent', { name: 'description', Type: Ext.data.SortTypes.asUCString }, { name: 'customers', Type: Ext.data.SortTypes.asUCString }, { name: 'username', Type: Ext.data.SortTypes.asUCString, mapping: 'customers[0].username' } ]
當我嘗試訪問customers[0].username
,它只檢索指定索引上的那些。 刪除索引號返回undefined
因為我認為它正在尋找要返回的索引。 如何正確檢索所有customers: []
並將其顯示到我的網格中,其結構如下:
{ xtype: 'gridpanel', store: oStore, viewConfig: { loadMask: false, enableTextSelection: true }, hideHeaders: false, bodyBorder: true, columns: [{ text: 'Customer', dataIndex: 'username', flex: 1 }, { header: '', xtype: 'actioncolumn', itemId: 'remove-player-btn', width: 50, sortable: false, resizable: false, menuDisabled: true, items: [{ icon: 'resources/img/x.png', tooltip: 'Remove Player', scope: oMe }], editor: { xtype: 'text', name: 'deleteRow' } }] }
您可以使用模型中可用的轉換函數。此轉換函數用於某些計算目的和映射響應數據以滿足我們的需要。例如,我將映射用戶名如下:
fields: [
{
name:'username',
convert:function(value,model)
{
return model.data.customers.username;
}
}
]
對id字段使用相同的技術。如果有任何問題,請回復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.