PDA

View Full Version : Combobox with store using ajax proxy json reader



wdieujus
6 Aug 2013, 2:33 PM
Im having issues loading a store into a combobox. Not sure if the Json is incorrectly formatted or my store. Please provide any feedback possible. Thanks!

Heres my json:

{"success":true,
"markets": [
{"display":"TEST","value":"TEST.xml"}]
}

heres my store:

var markets = Ext.create('Ext.data.Store', {
fields: [{name: 'display'}, {name: 'value'}],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'app/scripts/getMarketList.php',
reader: {
type: 'json',
root: 'markets'
}
}
});

And heres my combobox:
dockedItems: [
{
xtype: 'toolbar',
items: [{
xtype: 'combobox',
forceSelection: true,
editable: false,
fieldLabel: 'Choose Market,
store: markets,
displayField: 'display',
valueField: 'value'
}
]
}],

aaugen
6 Aug 2013, 11:17 PM
Hi,

Are you data populated in your store?
Check in JavaScript console if you send the right request and receive appropriate response. You can also try to put data directly in your store:


var markets = Ext.create('Ext.data.Store', {
fields: [{name: 'display'}, {name: 'value'}],
autoLoad: true,
data: [
{"display":"TEST1","value":"TEST1.xml"},
{"display":"TEST2","value":"TEST2.xml"}
]
});

wdieujus
7 Aug 2013, 7:21 AM
I'd rather not write the data directly in the store as the data is dynamic..

The php script, while also echo'ing the final json, also writes it to a file. I tried changing the url in the store to read the json instead and it worked. So the output json should be correct.

tobiu
7 Aug 2013, 8:14 AM
1) to check if your JSON is valid try: http://jsonlint.com/ (it is correct).

2) to debug this, use google chrome -> developer tools, go to the network tab and check if your request got send and what comes back.

3) if 2 is fine, log the store to the console and see what is inside