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

第一个问题: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;
				    }
				}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值