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());

猜你喜欢

转载自cainiao1923.iteye.com/blog/2342255
ext