Forum /
Ext GWT Community Forums (1.x) /
Ext GWT: Help & Discussion (1.x) /
Getting nested data in a store
Getting nested data in a store
I have 2 models Event and Media.(Event has many medias and media belongsTo Event)
This is the model of Event:
Ext.define("UnivMobile.model.Event", {
extend: "Ext.data.Model",
requieres:'UnivMobile.model.Media',
config: {
fields:[
{ name: 'id' },
{ name: 'titre'},
{ name: 'description'},
{ name: 'date_deb'},
{ name: 'date_fin'},
{ name: 'lieu'}
],
hasMany: [{
model: 'UnivMobile.model.Media',
name:'Media',
}]
}
});
And this is the model of Media:
Ext.define("UnivMobile.model.Media", {
extend: "Ext.data.Model",
config: {
fields:[
{ name: 'id' },
{ name: 'filename'},
{ name: 'dir'},
{ name: 'mimetype'},
{ name: 'filesize'},
{ name: 'created'},
{ name: 'modified'},
{ name: 'event_id'}
],
belongsTo: [{ model: 'UniMobile.model.Event', associationKey: 'event_id' }],
}
});
This is the store of Events:
Ext.define("UnivMobile.store.Events", {
extend: "Ext.data.Store",
config:{
model: "UnivMobile.model.Event",
proxy:{
type:'ajax',
url:'http://localhost/UniversiteCakeUploadEssai/events/web',
reader: {
type: 'json',
record:'Event',
}
},
autoLoad:true
}
});
This is the store of Medias:
Ext.define("UnivMobile.store.Medias", {
extend: "Ext.data.Store",
config:{
model: "UnivMobile.model.Media",
proxy:{
type:'ajax',
url:'http://localhost/UniversiteCakeUploadEssai/media/web',
reader: {
type: 'json',
record:'Media'
}
},
autoLoad:true
}
});
And finally this is JSON data of events:
[{"Event ":{"id":"6","titre":"AgileTour","description":"Decouvrir la m\u00e9thodologie Agile","date_deb":"","date_fin":"","lieu":"Esprit"},"Media ":[{"id":"53","filename":"149787_414631291941737_714868681_n.jpg","dir":"upload\/6","mimetype":"image\/jpeg","filesize":"10978","created":"2012-12-25 19:59:38","modified":"2012-12-25 19:59:38","event_id":"6"},{"id":"54","filename":"68596_414630785275121_726648910_n.jpg","dir":"upload\/6","mimetype":"image\/jpeg","filesize":"93849","created":"2012-12-25 20:00:32","modified":"2012-12-25 20:00:32","event_id":"6"},{"id":"55","filename":"3451_414631238608409_595777429_n.jpg","dir":"upload\/6","mimetype":"image\/jpeg","filesize":"62381","created":"2012-12-25 20:00:50","modified":"2012-12-25 20:00:50","event_id":"6"},{"id":"59","filename":"simpsons (1).mov","dir":"upload\/6","mimetype":"video\/quicktime","filesize":"99279","created":"2012-12-26 11:43:46","modified":"2012-12-26 11:43:46","event_id":"6"}]},{"Event ":{"id":"7","titre":"Blackberry Jam","description":"la nouvelle plateforme Blackberry 10 ","date_deb":"","date_fin":"","lieu":"Esprit"},"Media ":[{"id":"56","filename":"14281_10200182854122365_2051486553_n.jpg","dir":"upload\/7","mimetype":"image\/jpeg","filesize":"72591","created":"2012-12-25 20:06:55","modified":"2012-12-25 20:06:55","event_id":"7"},{"id":"57","filename":"559912_264352283687703_857349258_n.jpg","dir":"upload\/7","mimetype":"image\/jpeg","filesize":"121070","created":"2012-12-25 20:07:54","modified":"2012-12-25 20:07:54","event_id":"7"},{"id":"58","filename":"198386_4522570615889_511505037_n.jpg","dir":"upload\/7","mimetype":"image\/jpeg","filesize":"53981","created":"2012-12-25 20:08:10","modified":"2012-12-25 20:08:10","event_id":"7"}]}]
There are 2 events and each one have its medias.
In my view :
I can access to informatiosn event's(titre,description),but I cannot display Media and its informations,I get an empty array ,this is the code view:
Ext.define("UnivMobile.view.InfoEvents", {
extend: 'Ext.Container',
xtype:'events-show',
initialize:function(){
var store=Ext.getStore("Events");
store.load({
callback: function() {
var event = store.first();
console.log(event.get('Media'))
// event.Media.each(function(media) {
// console.log("Media id: " + media.getId());
// });
}
});
},
config:{
title: 'Information',
store:'Events',
items: [
{
id: 'content',
tpl: [
'<div style="margin-left:100px">{titre} </div>',
'{description}',
'{lieu}',
'{filename}'//I cannot display this
]
}
],
record: null
},
updateRecord: function(newRecord) {
if (newRecord) {
this.down('#content').setData(newRecord.data);
}
}
});
Please how can I display data of medias(filename.....) for each event???
Sencha is used by over two million developers. Join the community, wherever you’d like that community to be
or Join Us