PDA

View Full Version : Hierarchical JSON => Ext.data.Record



freepopo
3 Aug 2009, 5:50 PM
Hi there,

Is it possible to retrieve data from a hierarchical Json array ?

My Record is like this :

var Record_annees = Ext.data.Record.create([//{

{name: 'id'},
{name: 'name'},
{name: 2008, type: 'float'},
{name: 2009, type: 'float'},
{name: 2010, type: 'float'}
]);

And i would like to have it like that :

var Record_annees = Ext.data.Record.create([//{

{name: User{id}},
{name: User{name}},
{name: 2008, type: 'float'},
{name: 2009, type: 'float'},
{name: 2010, type: 'float'}
]);

Thank in advance of help, it's very important for me ~o)

saJoshua
3 Aug 2009, 7:06 PM
It doesn't make sense to me what you are trying to achieve? Please explain why you would like to create a record with :


{name: User{id}},
{name: User{name}},

mjlecomte
3 Aug 2009, 9:12 PM
show your json data. maybe you want "mapping" config.

freepopo
3 Aug 2009, 10:52 PM
Excuse me, here is some piece of the JSON object that i have to handle :


"USER_infos":
{"User":
{"id":"4","login":"patrick","matricule":"05001026","name":"patrick","prenom":"dupont"}
{"Group":
{"id":"5","name":"groupe A"}
}

saJoshua
3 Aug 2009, 11:02 PM
Hi,

Typically the Ext.data.Store stores sets of Ext.data.Records with the same structure. It's not a good idea to try and change the field definition on a record by record basis. JSON structure is nice and flexible so you define all sorts of javascript objects using it's notation, but Ext.data.Records have a very specific usage.

I can see that your example refers to "users" and "groups". Perhaps consider the following structure.


var users = new Ext.data.JsonStore({
fields: [{name:'id', type:'int'}, 'login', 'matricule', 'name', 'prenom', {name:'groupid', type:'int'}, 'groupname'],
root: 'USER_infos',
id : 'id'
});

var data = {"USER_infos":[{"id":4,"login":"patrick","matricule":"05001026","name":"patrick","prenom":"dupont", groupid:5,groupname:"groupe A"},
{id:5,login:"john",matricule:"05001037",name:"john",prenom:"doe", groupid:5,groupname:"groupe A"}]};

users.loadData(data);

users.each(function(rec){
console.log(rec.data);
})

Animal
3 Aug 2009, 11:10 PM
Excuse me, here is some piece of the JSON object that i have to handle :


"USER_infos":
{"User":
{"id":"4","login":"patrick","matricule":"05001026","name":"patrick","prenom":"dupont"}
{"Group":
{"id":"5","name":"groupe A"}
}


That's not JSON.

mjlecomte
4 Aug 2009, 5:11 AM
Your first post does not match your json data, where's the 2008, 2009, etc?

Did you read about mapping in the API docs?