Here's a quick answer: you can get to a variable inside of a specific index of of c3col like this:
wDefaults.c3col[0].wid
You're actually mixing objects and arrays and arrays of objects, which is going to make you have to switch accessor syntaxes - the above is objectName.array[index].variableName
Here's a map:
- var wDefaults = { // this is a javascript Object
- "skin":1, // this is an object property accessible with . notation (wDefaults.skin)
- "pagewidth":"960px",
- "c1col":[ // this is an array with a single index, c1col[0],
- // which has the value of the following object:
- {"wid":"w001","pcol":0,"wpos":0,"wclosed":"false","wcollapsed":"true"}
- // this object is accessible with a mix of . and [] notation: (wDefaults.c1col[0].wid)
- ],
- "c3col":[
- {"wid":"w002","pcol":0,"wpos":0,"wclosed":"false","wcollapsed":"false"}, //wDefaults.c3col[0].wid
- {"wid":"w003","pcol":0,"wpos":1,"wclosed":"false","wcollapsed":"false"}, //wDefaults.c3col[1].pcol
- {"wid":"w004","pcol":0,"wpos":2,"wclosed":"false","wcollapsed":"false"}, //wDefaults.c3col[2]
- {"wid":"w005","pcol":1,"wpos":0,"wclosed":"false","wcollapsed":"false"}, // etc.
- ]
- }
In order to alter any of the objects, you just use the method appropriate to the data structure, for example with objects you can use .notation and =, like this:
- wDefaults.c3col[5].wcollapsed = true; // note boolean values are not strings, don't use quotes
If you want to add an object the c3col array, then you could use the
javascript array methods, like array.push(x), which adds a new index at the end of the array:
- var tempObjectToAdd = {wid : "w012", pcol : 2, wpos : 2, wclosed :"false", wcollapsed :"false"}
- wDefaults.c3col.push(tempObjectToAdd);
I did a screenshot of a bunch of this using firebug, which I'd recommend as a way to test this stuff without writing test code (just declare your object and then load the page and make watch statements like "wDefaults.c3col[5].wcollapsed"