PDA

View Full Version : JSONP fills a nested list



Kurt001
3 May 2011, 2:41 PM
Hi there,
I am looking for a way to get a nested list filled with a JSONP.request.

So far I have:

var myJRequest = function() {
Ext.util.JSONP.request({
url: 'http://thisWebID/configuration',
callbackKey: 'jsoncallback',
params: { format: 'json', jsoncallback: 'Ext.util.JSONP.callback' },
callback: function(result) {
console.log(result)
}
});
}; This works fine. It calls the server with

http://thisWebID/configuration?format=json&jsoncallback=Ext.util.JSONP.callbackNow I would like to fill a nested list with the data from the callback.

Ext.setup({
onReady : function() {
// store with data
Ext.regModel('ListItem', {
fields: [{name: 'text', type: 'string'}]
});
var store = new Ext.data.TreeStore({
model: 'ListItem',
proxy: {
type: 'scripttag',
url : 'http://thisWebID/configuration',
callbackParam: 'jsoncallback',
extraParams: { format: 'json', jsoncallback: 'Ext.util.JSONP.callback' },
reader: {
type: 'tree',
root: 'configuration'
}
}
});
var nestedList = new Ext.NestedList({
fullscreen: true,
title: 'NestedList',
displayField: 'text',
store: store
});
}
});Now the following is added to the call:

http://thisWebID/configuration?format=json&jsoncallback=Ext.util.JSONP.callback,stcCallback1001But as the JSONP result seems to be ok, the only problem is, that the nested list keeps telling me that No Items Available

This is my result from the JSONP call:

Ext.util.JSONP.callback,stcCallback1001({ configuration":{"data-types":{"data-type":[{"@name":"Quantity","@id":"1","@unit":"1"},{"@name":"Weight","@id":"2","@unit":"kg"}],"attributes":[{"@name":"Attribute","@id":"4"},{"@name":"RawData","@id":"655"},{"@name":"RawData2","@id":"656"}]},"device-types":{"device-type":[{"@name":"Holder","@id":"5","data-streams":{"data-stream":[{"@name":"Offer","@id":"6","@data-type":"Attribute"},{"@name":"Mapping","@id":"7","@data-type":"Attribute"},]},"sources":{"source":{"@name":"Post","@id":"13","data-streams":{"data-stream":[{"@name":"Offer","@id":"14"},{"@name":"Mapping","@id":"15"},]}}}}]}}})How can I populate a nested list with JSONP?

Best regards

Kurt

martinbroos
5 May 2011, 4:33 AM
If i run your returned JSON through a validator it isn't good ..
look at http://www.jsonlint.com/

I think your JSON should match the example given in the documentation :



// store with data
var data = {
text: 'Groceries',
items: [{
text: 'Drinks',
items: [{
text: 'Water',
items: [{
text: 'Sparkling',
leaf: true
},{
text: 'Still',
leaf: true
}]
},{
text: 'Coffee',
leaf: true
},{
text: 'Espresso',
leaf: true
},{
text: 'Redbull',
leaf: true
},{
text: 'Coke',
leaf: true
},{
text: 'Diet Coke',
leaf: true
}]
},{
text: 'Fruit',
items: [{
text: 'Bananas',
leaf: true
},{
text: 'Lemon',
leaf: true
}]
},{
text: 'Snacks',
items: [{
text: 'Nuts',
leaf: true
},{
text: 'Pretzels',
leaf: true
},{
text: 'Wasabi Peas',
leaf: true
}]
},{
text: 'Empty Category',
items: []
}]
};


A solution to accomplish this can be to load a ajax call and let the php get the JSONP file and reformat it the way is shown in the example.