ext Model里面属性是对象的解决方案



 像这种,model里面属性为对象的,可以这么玩

 

方法一:

 

   
			   Ext.define('App.model.Model', {
		            extend: 'Ext.data.Model',
// 		            requires: [
// 		                'App.model.Task'
// 		            ],
		            fields: [
		                {name: 'task' ,type:'auto'},
		                {name: 'task.createTime' ,mapping:'task.createTime'},
		                {name: 'processInstance'},
		                {name: 'processDefinition'},
		                {name: 'title', type: 'string'}
		            ]

		        });

 

{ header: '创建时间', dataIndex: 'task.createTime', align: 'center', flex:1}

 参考

http://stackoverflow.com/questions/10500367/extjs-model-fields-with-subfields 写道
Thanks to @sha - here is the answer I needed :)

Model

fields:[

{name: 'id', type: 'int'},
{name: 'title', type: 'string'},
{name: 'description', type: 'string'},
{name: 'priority', type: 'auto'},
{name: 'code', type: 'string', mapping:'priority.code'},
{name: 'createdBy', type: 'auto'},

]
Gird Panel

columns:[

{header:'Title', dataIndex:'title', flex:1},
{header:'Description', dataIndex:'description'},
{header:'Priority', dataIndex:'code'}

],

 

 

 

 

 

如果,属性是集合的,就用hasMany吧,

http://stackoverflow.com/questions/14756012/extjs-nested-model 写道
 
Ext.define("ResponseModel",{
extend:'Ext.data.Model',
fields:[],

hasMany:[{
    model:'Sromain',
    name:'sromain'},{
    model:'Branch',
    name:'branches'}]});

Ext.define("Sromain",{
extend:'Ext.data.Model',
fields:['corporation','dbName','prijmyCelk','nakladyCelk','ziskCelk','neuhrVydCelk','neuhrPrijCelk','dph'],
belongsTo:'ResponseModel'});

Ext.define("Branch",{
extend:'Ext.data.Model',
fields:['branch_name','branch_code','strediskoprijmyCelk','strediskonakladyCelk','strediskoziskCelk','strediskoneuhrVydCelk','strediskoneuhrPrijCelk','streddphCelk'],
belongsTo:'ResponseModel'});

var firstRecord = store.getAt(0);
console.log(firstRecord.branches());

console.log(firstRecord.sromain());

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值