Hybrid View
-
21 Feb 2008 3:53 AM #1
Display a ComboBox with a Json
Display a ComboBox with a Json
Hye,
I'm a new user of extjs, and I've got an issue.
I have this Json :
I'm trying to display this in this comboBox using a Ext.data.Store and a Ext.data.JsonReader like this :Code:{"total":"5", "corporates":[{"cop_id":"2","cop_name":"burode"},{"cop_id":"3","cop_name":"tag"},{"cop_id":"1","cop_name":"tagattitude"},{"cop_id":"4","cop_name":"test"},{"cop_id":"5","cop_name":"test2"}]}
corporateList is here in my php file :Code:var ds = new Ext.data.Store({ reader: new Ext.data.JsonReader({ root: 'corporates' , totalProperty: 'total' }, [{name:'cop_id'}, {name:'cop_name'}]) }); var comboBox = new Ext.form.ComboBox({ store: ds, mode: 'local', valueField: 'cop_id', displayField: 'cop_name', applyTo: 'corporateList' });
The matter is that nothing is inside my ComboBox....PHP Code:<div>
<input type="text" id="corporateList" size="20"/>
</div>
Is there someone to help me on this ?
Thanks a lot.
-
27 Feb 2008 1:39 AM #2
Hi,
I've the same problem that yours but I used JsonStore in place of JsonReader.
Here is my JSON response from get-thema.php :
I'm trying to display this JSON in a combobox :Code:{"thema":[{"id":1,"name":"Foret"},{"id":2,"name":"Emploi"}]}
[CODE]var themaList = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: './get_thema.php'}),
autoLoad: true,
reader: new Ext.data.JsonStore({
root: 'thema',
fields: [
{name: 'id'},
{name: 'name'}
]
})
});
var combo = new Ext.form.ComboBox({
fieldLabel: 'Organisme',
store: themaList,
displayField: 'name',
valueField: 'id',
forceSelection: true,
editable: false,
mode: 'local',
triggerAction: 'all',
selectOnFocus: true,
emptyText: 'S
-
27 Feb 2008 1:51 AM #3Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
You need to load the store yourself if you set mode:'local'.
-
27 Feb 2008 2:00 AM #4
Thanks for help,
autoLoad option is not the same that myStore.load() method ?
With the two configurations, my combobox is empty.
-
27 Feb 2008 2:08 AM #5Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
It would help if you used:
Code:var themaList = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({url: 'test2.json'}), autoLoad: true, reader: new Ext.data.JsonReader({ root: 'thema', fields: [ {name: 'id'}, {name: 'name'} ] }) });
-
27 Feb 2008 2:19 AM #6
Great, thank you.
It's working now.
But I think I don't understand the difference between JsonReader and JsonStore.


Reply With Quote