-
24 Nov 2011 2:53 AM #1
Loading selectfield from an external json file
Loading selectfield from an external json file
Hi Sencha People
Is there a way to populate a select field by means of an external json file?
then doing ...Code:var store = Ext.create('Ext.data.Store', { model: 'ListItems', storeId: 'itemStore', proxy: { type: 'ajax', url: 'itemList.json', reader: { type: 'json' } }, autoLoad: true });
How does one bind the the item_id to the item_name (as in the JSON below) and list it?Code:var item_ddn = new Ext.field.Select({ name: 'item_ddn', label: 'Items Listed:', store: store });
JSON code...
**Appreciated**Code:[ { "item_id" : "113", "item_name" : "Metro Goldwyn Mayer" }, { "item_id" : "106", "item_name" : "M-Net Action" } ]
-
24 Nov 2011 9:06 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,646
- Vote Rating
- 434
Set the valueField config to 'item_id' and the displayField config to 'item_name' on your Select field. I would also set the idProperty on your Model to 'item_id' and you should have things setup pretty well. One last thing instead of doing 'new Ext.field.Select', you should do the ST2 way and do "Ext.create('Ext.field.Select' "
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
25 Nov 2011 12:47 AM #3
Awesomeness
Awesomeness
Hi Mitchell Simoens,
Brilliant - thank you again. I did some more reading, had some more coffee
and trial'n error
sessions and got it working nicely ...
Here's the code (for anyone else out there looking for this) ... pretty straight forward once you get the hang of it.
Code:Ext.application({ name: 'Dynamic Menu', launch: function() { Ext.define('MenuItems', { extend: 'Ext.data.Model', idProperty: 'item_id', fields: [ {name: 'item_id', type: 'string'}, {name: 'item_name', type: 'string'} ] }); var store = Ext.create('Ext.data.Store', { model: 'MenuItems', storeId: 'MenuStore', proxy: { type: 'ajax', url: 'menu.json', reader: { type: 'json' } }, autoLoad: true }); var bundle_ddn = Ext.create('Ext.field.Select', { name: 'item_ddn', label: 'Bouquet:', valueField: 'item_id', displayField: 'item_name', store: store }); var formBase = { scroll: 'vertical', title: 'Settings', items: [ bundle_ddn ] }; Ext.create('Ext.tab.Panel', { fullscreen: true, items: [ formBase ] }); } });
Regards,
Riyaad
-
25 Nov 2011 1:23 AM #4
PS: Does anyone know if this has been resolved?
http://www.sencha.com/forum/showthre...-no-selection.
I'm assuming there's yet to be a fix for STv2 as I'm getting the same behavior...


Reply With Quote