arrays - loading data from a json -
i have data available want load this:
{ "success": true, "message": null, "total": null, "data": [{ "clocktypes": ["_12", "_24"], "speedtypes": ["mph", "kmph"], "scheduletypes": ["default", "auto"] }]}
i normaly load data this
ext.define('myapp.store.combotimezone', { extend: 'ext.data.store', constructor: function(cfg) { var me = this; cfg = cfg || {}; me.callparent([ext.apply({ autoload: true, storeid: 'myjsonstore5', proxy: { type: 'ajax', url: 'json/timezone.json', reader: { type: 'json', root: 'data' } } }, cfg)]); }});
now clocktypes 1 record in combobox. how can 2 records: _12 , _24 in combobox?
your root
should be... data.clocktypes
-think- ( though i'm not sure if work. )
hijacking ajax call load data bit awkward, since thats not right format store consume( it? )
ideally want...
{ "success": true, "message": null, "total": null, "data": [{ name: "_12", name:"_24"] }]} constructor: function(cfg) { var me = this; cfg = cfg || {}; me.callparent([ext.apply({ autoload: true, storeid: 'myjsonstore5', valuefield:'name', displayfield:'name', proxy: { type: 'ajax', url: 'json/timezone.json', reader: { type: 'json', root: 'data' } } }, cfg)]); }});
though mean end more ajax calls. alternatively, if you've got heart set on populating 3 comboboxes (i'm kinda guessing that's trying ) 1 ajax call, need generate stores dynamically based off data ext.request()
however if cant mess data, can...
ext.define('myapp.store.combotimezone', { extend: 'ext.data.store', constructor: function(cfg) { var me = this; cfg = cfg || {}; ext.define('tz', extend: 'ext.data.model', fields: [{ name: 'name' }]) me.callparent([ext.apply({ autoload: true, model: 'tz', storeid: 'myjsonstore5', proxy: { type: 'ajax', url: 'json/timezone.json', reader: { type: 'json', root: 'data' } } }, cfg)]); //hacky, works guess ext.ajax.request({ url: 'my.json', success: function(response) { var text = response.responsetext; var json = ext.json.decode(text); for(var =0);i<json.data.lenght();i++;){ ext.data.storemanager.lookup('myjsonstore5').add(ext.create('tz',{name:json.data[i]})) } } }); } });
*barrring typos create bugs.
basically call url, data raw json, , process format store can read.
it's bit of hack unfortunately.
Comments
Post a Comment