Hello,
and i would like to handle it in a store. So. Here's my problem.
I defined a model called product.
then i defined a root model
Above i used "has Many", because i think it's correct to use, but actually i have no idea. I also put requires 'Myapp.model.ProductModel' because they say it's something to do (but i don't know why).
Handling JSON message in store with many sub-association
Here's my problem. I receive from the server a message of such shape
Code:
[{
id: 2,
description: "nicenice",
idCustomer: 1,
products: [{
id: 3,
name: "foo",
description: "ff"
},{id: 5,
name: "foo2",
description: "aaa"
}
]
},{
id: 8,
description: "ugly",
idCustomer: 4,
products: [{
id: 4,
name: "paa",
dextion: "ghh"
},{id: 6,
name: "htht",
description: "jj"
}
]
}]
and i would like to handle it in a store. So. Here's my problem.
I defined a model called product.
Code:
Ext.define('Myapp.model.ProductModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.Field'
],
fields: [
{
name: 'id'
},
{
name: 'name'
},
{
name: 'description'
}
]
});
then i defined a root model
Code:
Ext.define('Myapp.model.PlantModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.Field',
'Ext.data.association.HasMany',
'Myapp.model.ProductModel'
],
uses: [
'Myapp.model.ProductModel'
],
fields: [
{
name: 'id'
},
{
name: 'description'
},
{
name: 'idCustomer'
}
],
hasMany: {
associationKey: 'products',
model: 'Myapp.model.ProductModel',
foreignKey: 'id',
name: 'products'
}
});
Above i used "has Many", because i think it's correct to use, but actually i have no idea. I also put requires 'Myapp.model.ProductModel' because they say it's something to do (but i don't know why).
Then i defined a store and i set Plant as its model.
but it doesn't work. If i fetch the elements from the store, i just receive the first "part" of the model. I receive the "id", "description" and "idCustomer".
How could i retrieve the other part?
what am i missing?
Handling JSON message in store with many sub-association
Aucun commentaire:
Enregistrer un commentaire