When you're talking about associations it's better to use concrete examples because of the way the name generation works.
Server returns:
You can do this:
Code:
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['name']
});
Ext.define('Post', {
extend: 'Ext.data.Model',
fields: ['content', {
name: 'userId',
reference: {
type: 'User',
inverse: 'comments'
}
}]
});
Ext.onReady(function () {
User.load(17, {
callback: function(rec) {
var comments = rec.comments();
console.log(comments.first().get('content'));
}
});
});
Server returns:
Code:
{
"id": 17,
"name": "Foo Bar",
"comments": [{
"id": 1,
"userId": 17,
"content": "Foo"
}]
}
Aucun commentaire:
Enregistrer un commentaire