PDA

View Full Version : JSON Help



Tuckerific
28 Mar 2010, 2:37 PM
How do I change the value of a json object?

I have a json store. I want to loop through it and change the values of the different properties. Here is an example of what I'm trying to do, which obviously doesn't work.



var records = ddSource.dragData.selections;

for(var i=0; i<records.length; i++){
records[i].name = "Name Changed";
}




Any help that anyone could give would be really appreciated. Thanks!

fay
28 Mar 2010, 2:40 PM
Have you tried using FireFox/FireBug, putting a breakpoint within the for loop, and checking what is accessible from "records[i]" in the watch window?

Tuckerific
28 Mar 2010, 3:11 PM
I've done so, and it shows all of the properties of the json object. It doesn't say anything about read/write etc though. Any other thoughts? I didn't know if EXTJs was making those json objects immutable perhaps.

firefoxSafari
28 Mar 2010, 8:35 PM
Are these instances of the actual Record class? If so, I think you need to use the set method on the record. Something like



records[i].set('name', 'Name Changed');
records[i].commit();

Tuckerific
29 Mar 2010, 2:06 AM
That was exactly what I was looking for. Thanks!