PDA

View Full Version : Combobox & Json



jimmyphp
28 Apr 2007, 7:03 AM
I need to create a combobox with data from server, this is my code:

datastore:


var comboStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'comboboxsql.php'
}),
reader: new Ext.data.JsonReader({
root : 'myData'
}, ['value','text'])
});


combobox:


new Ext.form.ComboBox({
width:175,
fieldLabel : "Supervisore",
name : "id_supervisore",
store : comboStore.load({params:{code: "3"} }),
displayField : "text" ,
valueField : "value"
}
)

and server response


{"MyData":[["1","Amministratore"],["7","Burger"],["3","Marcellini"],["25","Ranghetti"]]}


Sorry for my english.

Thank's in advance.

Animal
28 Apr 2007, 7:12 AM
And?

jimmyphp
28 Apr 2007, 7:19 AM
Thank's for quick response.

firebug:

this.store has no properties

Animal
28 Apr 2007, 9:45 AM
Well yes, you are telling it that its store is whetever is returned from "comboStore.load({params:{code: "3"} })"

What does load return?

http://www.extjs.com/deploy/ext/docs/output/Ext.data.Store.html#load

jimmyphp
2 May 2007, 2:48 AM
when i call load there are e server request with correct POST params.
server response:


{"MyData":[["1","Amministratore"],["7","Burger"],["3","Marcellini"],["25","Ranghetti"]]}


Thank's

jsakalos
2 May 2007, 3:12 AM
It's written in doc that load method of store returns void. Do it like this:


new Ext.form.ComboBox({
width:175,
fieldLabel : "Supervisore",
name : "id_supervisore",
store : comboStore,
displayField : "text" ,
valueField : "value"
}
)
comboStore.load({params:{code: "3"} });

jimmyphp
2 May 2007, 3:33 AM
a simple method to populate combo by json from server?

jsakalos
2 May 2007, 3:40 AM
Set mode:'remote' in combo config and it loads everytime the user click trigger.

jimmyphp
2 May 2007, 3:53 AM
I have tried with remote but i have the same error.
If i set store without load no error but no data.

Anyone have example?

Thank's

jsakalos
2 May 2007, 3:59 AM
Have you specified triggerAction:'all' ?

jimmyphp
2 May 2007, 4:11 AM
WORK. Many thank's

jsakalos
2 May 2007, 4:28 AM
Super!

I'm glad I helped.