Last November, there was a bug report in JSON Table Editor‘s support page. The person note that the table editor unable to load non-linear JSON. If he loaded the following JSON, the table is only showing two columns:
[{ "name" : "gggg", "desc" : "gggg"}, { "text" : "gggg" }, { "text" :"gggg" }, { "text" : "gggg" }]
So today I finally have the time to look at this problem. After a quick look, I realized that it’s a simple problem. Previously, the ExtJS Store is initialized with the first object in the JSON array. Now, we must iterate all items inside the array and combining all of their attributes.
We do it as follows:
// ...... CODE SNIP ...... //obj is the JSON array var initObj = obj[0]; //copy all properties' name into initObj Ext.each(obj, function(item){ for (var key in item) { if (initObj[key] == undefined) { if (typeof(item[key]) == "number") initObj[key] = 0; else initObj[key] = ""; } } }); //initialize the ExtJS Store with initObj initStoreWithObject(initObj); // ...... CODE SNIP ......
And it works:
Happy holidays all!
Cheers,
Hardono
loading...
About Hardono
Incoming Search
bugs, extjs, javascript