extjs4.1 grid columns處理幾個小問題(第一:combobox 中的store帶引數到後臺,第二model資料是一個object)
阿新 • • 發佈:2019-02-18
第一個問題:combobox中的store可以通過帶引數來區分。
第二個問題:Ext.define("zyc.view.test.ComboboxStoreParam",{ extend:'Ext.panel.Panel', title : '測試',//標題 alias: 'widget.comboboxstoreparam', frame : true,//面板渲染 width : 700, height: 480, bodyStyle: { background: 'whiter', padding: '10px' }, items:[{ xtype:'combobox', store: 'test.User', queryMode: 'local', displayField: 'name', listeners:{ render:function(cb,eOpts ){ var store=cb.getStore(); store.proxy.url+='?type=ComboboxStoreParam', console.debug(store.proxy.url); } } }] })
後臺返回的資料是這樣的:
[{"age":20,"email":{"age":226,"name":"2261354-99","type":226},"id":1,"name":"關耳丘山川1"},{"age":30,"email":{"age":233,"name":"2261354-88","type":223},"id":2,"name":"關耳丘山川2"},{"age":40,"email":{"age":244,"name":"2261354-77","type":244},"id":3,"name":"關耳丘山川3"},{"age":50,"email":{"age":266,"name":"2261354-66","type":266},"id":4,"name":"關耳丘山川4"},{"age":0,"email":null,"id":0,"name":""}]
email是一個物件。
所以在model中這樣寫:
Ext.define('zyc.model.User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string',sortable : true},
{name: 'age', type: 'int',sortable : true},
{name: 'email.type', type: 'int',sortable : true}
]
});
view中這樣:
Ext.define("zyc.view.List",{ extend:'Ext.grid.Panel', title : 'Grid Demo',//標題 alias: 'widget.userlist', frame : true,//面板渲染 width : 600, height: 280, columns : [ //列模式 {text:"Name",dataIndex:'name',width:100}, {text:"age",dataIndex:'age',width:100}, {text:"email",dataIndex:'email.type',width:350, field:{ xtype:'textfield', allowBlank:false } } ], tbar :[ {xtype:'button',text:'新增',iconCls:'table_add'}, {xtype:'button',id:'delete',text:'刪除',iconCls:'table_remove'}, {xtype:'button',text:'修改',iconCls:'table_edit'}, {xtype:'button',text:'檢視',iconCls:'table_comm'} ], dockedItems :[{ xtype:'pagingtoolbar', store:'Users', dock:'bottom', displayInfo:true }], plugins:[ Ext.create("Ext.grid.plugin.CellEditing",{ clicksToEdit : 2 }) ], selType:'checkboxmodel',//設定選擇模式 multiSelect:true,//執行多選 store : 'Users', initComponent:function(){ console.debug(this.getStore()); this.callParent(arguments); } });
問題三:有時候,後天返回的資料是一個物件,這個物件是list,這時候就要處理了。
後天給的資料:
[{"age":20,"animals":[{"age":"test","name":"licy"},{"age":"test","name":"lili"}],"email":{"age":226,"name":"2261354-99","type":226},"id":1,"name":"關耳丘山川1"},{"age":30,"animals":[],"email":{"age":233,"name":"2261354-88","type":223},"id":2,"name":"關耳丘山川2"},{"age":40,"animals":[],"email":{"age":244,"name":"2261354-77","type":244},"id":3,"name":"關耳丘山川3"},{"age":50,"animals":[],"email":{"age":266,"name":"2261354-66","type":266},"id":4,"name":"關耳丘山川4"},{"age":0,"animals":[],"email":null,"id":0,"name":""}]
裡面的animals是一個list物件
model程式碼
Ext.define('zyc.model.User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string',sortable : true},
{name: 'age', type: 'int',sortable : true},
{name: 'email.type', type: 'int',sortable : true},
{name: 'animals', type: 'object',sortable : true}
]
/*hasMany:{
model: 'animal',
name : 'Animal'
//filterProperty: 'teacher_Id'
}*/
});
view 中grid可以這樣寫:
{text:"animal",dataIndex:'animal',width:350,
renderer: function(value, metaData, record, row, col, store, gridView){
var animals =record.data.animals;
var newValues=new Array();
for(var i=0;i<animals.length;i++){
newValues.push(animals[i].name);
}
var newValue=newValues.join(',');
console.debug(animals);
console.debug(newValue);
return newValue;
}
}