PDA

View Full Version : Nested JSON data handling with jsonstore and XTemplate



ktakahashi
22 Nov 2010, 4:54 AM
Hi all,
I am using jsonstore and Ext.XTemplate to build my own web-site but I have a trouble.
I can not handle the nested JSON data using jsonstore and XTemplate as follows:


[
{"child1": {"a":"1","b":"2"}},
{"child1": {"a":"100","b":"200"}}
]


And, I wrote the code as follows:


var employeeDvStore = {
xtype : 'jsonstore',
autoLoad : true,
storeId : 'employeeDv',
// proxy : employeeStoreProxy,
url : 'test.json',
fields : [
{ child1 : "child1", mapping "child1"},
{ a : "a", mapping "a" },
{ b : "b", mapping "b" }
]
};

var foobar = new Ext.XTemplate(
'<tpl for=".">',
'<tpl for="child1">',
'<div class="emplWrap" id="employee_{a}">',
'<div><span class="title">TEST:</span> {b}</div>',
'</div>',
'</tpl>',
'</tpl>'
);

But these code did not work correctly. FireBugs dumped "child1 is not defined." message
I checked the connection information whether or not to be received the JSON data by FireFox. The result is that FireFox correctly received the JSON data from my server.
I assume that my mistake is in the jsonstore.field but I can not find out how to write my jsonstore.field to handle as stated above the nested JSON data.

Any advices?

Regards,
TKazushi

Condor
23 Nov 2010, 7:18 AM
You probably want:

var employeeDvStore = {
xtype: 'jsonstore',
autoLoad: true,
storeId: 'employeeDv',
proxy: employeeStoreProxy,
url: 'test.json',
fields: [{
name: "a",
mapping "child1.a"
},
{
name: "b",
mapping "child1.b"
}]
};
var foobar = new Ext.XTemplate(
'<tpl for=".">',
'<div class="emplWrap" id="employee_{a}">',
'<div><span class="title">TEST:</span> {b}</div>',
'</div>',
'</tpl>',
'</tpl>'
);