View Full Version : JSON Combobox

30 Oct 2009, 9:11 AM
Read so many post on this issue and still can't get mine to work.

Here's my code:

var regionStore = new Ext.data.JsonStore({
root : 'results',
autoLoad : true,
totalProperty : 'total',
id : 'id',
remoteSort : true,
fields: [
{name : "id", type: 'int', mapping: 'id'},
{name : "text", type: 'string', mapping: 'text'}
url : 'index.php?eID=tx_supersearch_pi1&mode=getComboRegions'


var regionCombo = new Ext.form.ComboBox({
store : regionStore,
displayField : 'text',
valueField : 'id',
typeAhead : true,
mode : 'local',
triggerAction : 'all',
emptyText : 'Select a location...',
selectOnFocus : true,
width : 130,
listWidth : 130,
iconCls: 'no-icon'

var tabToolBar = new Ext.Toolbar ({
items : [
new Ext.Toolbar.TextItem ("Jump to another location to focus your search: "),

and here's my JSON:

({"total":"4","results":[{"id":"7900","text":"England & Wales"},{"id":"8363","text":"France & Belgium"},{"id":"7901","text":"Ireland"},{"id":"7899","text":"Scotland"}]});

Yet nothing in the combobox. Am I missing something obvious here? Also tried it with a scripttagproxy on the url and same result.

30 Oct 2009, 9:36 AM
where's your metaData in your JSON?

scrap that, i really need to read posts properly :)

what happens if you do
regionStore.getCount() in firebug

4 Nov 2009, 2:38 AM
I get "ReferenceError: regionStore is not defined". Which is odd considering the Net module of firebug shows the request was made and the JSON returned.

4 Nov 2009, 2:51 AM
You're trying to use a remote JSON store with a local ComboBox (http://www.extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox), maybe the problem is that.

4 Nov 2009, 3:09 AM
Tried changing it and no luck - get the loading animation when you click the drop down arrow and then nothing. The call is made to the server and the JSON successfully returned though.

4 Nov 2009, 4:27 AM
That's not valid JSON (try running it through jslint.com)!

It should be:

{"total":"4","results":[{"id":"7900","text":"England & Wales"},{"id":"8363","text":"France & Belgium"},{"id":"7901","text":"Ireland"},{"id":"7899","text":"Scotland"}]}

4 Nov 2009, 4:46 AM
DOH! you know what it was? I'd re-used some code from a script tag proxy thing I set up for another part of the code and forgot to remove the brackets. Thanks Condor - always to the rescue :)