PDA

View Full Version : How to save nested model



ktare
13 Jul 2015, 10:12 AM
Our webservice accepts data in below format,


{
"department": {
"name": "service"
},
"type": {
"value": "email",
"subtype": {
"value": "compose"
}
}
}

As you see it has nested models.
This is my main model.


Ext.define('Agent.model.rest.Email', {
extend: 'Ext.data.Model',
alias: 'data.field.rest.rest-email',


hasOne: [
{
model: 'Agent.model.Department',
associationKey: 'department',
getterName: 'department'
},
{
model: 'Agent.model.activity.Type',
associationKey: 'type',
getterName: 'type'
}
]
}


below is Department model

Ext.define('Agent.model.Department', { extend: 'Ext.data.Model',
alias: 'data.field.department',


fields: [
{ name: 'name', type: 'string' },
]
});

Type model

Ext.define('Agent.model.activity.Type', { extend: 'Ext.data.Model',
alias: 'data.field.activity-type',


fields: [
{ name: 'value', type: 'string' },
{ name: 'internalValue', type: 'int' }
],


hasOne: {
model: 'Agent.model.activity.SubType',
associationKey: 'subtype',
getterName: 'subtype'
}
});

Subtype model

Ext.define('Agent.model.activity.SubType', { extend: 'Ext.data.Model',
alias: 'data.field.activity-subtype',


fields: [
{ name: 'internalValue', type: 'int' },
{ name: 'value', type: 'string' }
]

});

How do I save my main model 'Agent.model.rest.Email', so that it posts in the nested json format, as mentioned at start of this post?

I am using ExtJS 5.1

ktare
13 Jul 2015, 10:20 AM
Admin: Please remove this thread. I accidently posted it in ExtJs 4 group.