browse by category or date

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:

load-non-linear-json

Happy holidays all!

Cheers,
Hardono

GD Star Rating
loading...
Loading Non-Linear JSON, 4.0 out of 5 based on 1 rating

Possibly relevant:

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Incoming Search

bugs, extjs, javascript

1 Trackback

 

No Comment

Add Your Comment