PDA

View Full Version : Add a Field to a Store, and use each Records index to find the value



MattBlooJeans
27 Apr 2008, 8:56 PM
Hey all,

What I'm trying to do is add a new field in a Store object which uses the Index of the JsonStore data to compute the value for the new field. Sounds confusing but it's really not. It's pointless to send the data in the Ajax Call, because I can do it all client side as long as I know the Records Index number.

Ajax Data

[
{"f1":1234,"f2":56789,"f3":0123}, //index=0
{"f1":4567,"f2":89012,"f3":3456}, //index=1
{"f1":7890,"f2":12345,"f3":6789} //index=2
]


What I have right now

var store = new Ext.data.JsonStore({
url: 'ajax.php',
fields: [
'f1',
'f2',
'f3'
]
});
var id_to_value= ['a','b','c'];
store.each(function(record){
record.set('f4',id_to_value[record.id]);
});


What I'm trying to do
The 0,1,2 represents the index for the Record.
Store Data should look something like:


[
{"f1":1234,"f2":56789,"f3":0123,"f4":id_to_value[0]}, //index=0
{"f1":4567,"f2":89012,"f3":3456,"f4":id_to_value[1]}, //index=1
{"f1":7890,"f2":12345,"f3":6789,"f4":id_to_value[2]} //index=2
]


Cheers,
-Matt