PDA

View Full Version : Problem displaying nested json when the inner root is 'data'



cahello
19 Jul 2012, 10:40 AM
My json is:


{ result:[{
"size": 123,
"total": "Ed",
"data": [{
"wfAborted": 500,
"total": 1000,
}]
}]
}


My extjs code is:


Ext.define("Result", {
extend: 'Ext.data.Model',
fields: [
'size', 'total'
],


hasMany: {model: 'WFData', name: 'data'},
});


Ext.define("WFData", {
extend: 'Ext.data.Model',
fields: [
'wfAborted', 'total'
],
belongsTo: 'Result'
});

var store = new Ext.data.Store({
model: "Result",
proxy: {
type: 'rest',
url : 'path to the json file',
reader: {
type: 'json',
root: 'result'
}
},

});


store.load({
callback: function() {
//the user that was loaded
console.log("Loading store again:");
var result = store.first();
console.log("Orders of size " + result.get('size') + " and total " + result.get('total') + ":");
//iterate over the Orders for each User
result.data().each(function(order) {
console.log("Order ID: " + order.get('wfAborted') + ", which contains total items= " + order.get('total'));
});
}
});

When the 'name' is declared as 'data', i get the error "b is undefined". When I replace 'data' with anything else, the error is resolved. I have to use 'data' because the json string is returned by the rest call, and the second root is 'data'.

Any suggestions??