您的位置:首页 > 移动开发 > Objective-C

extjs4.1 grid columns处理几个小问题(第一:combobox 中的store带参数到后台,第二model数据是一个object)

2013-07-15 22:34 399 查看
第一个问题: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;
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐