Extjs Hasone Association
I have Person model, it contains id, first_name, last_name etc and merital_id field. I also have Merital model contains only 2 field: id and title. Server responses JSON like: {
Solution 1:
You should be using ExtJS Models, and Associations, in particular the HasOne association.
Documentation:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.association.HasOne
Example:
http://jsfiddle.net/el_chief/yrTVn/2/
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: [
'id',
'first_name',
'last_name'
],
hasOne: [
{
name: 'marital',
model: 'Marital',
associationKey: 'marital' // <- this is the same as what is in the JSON response
}
],
proxy: {
type: 'ajax',
url: 'whatever',
reader: {
type: 'json',
root: 'items' // <- same as in the JSON response
}
}
});
Post a Comment for "Extjs Hasone Association"