i'm using sencha architect testing purposes. added list view, connected store, connected model. store configured load following json data:
{ "data": { "blacklist":[ "word 1", "word 2", "word 2" ] } } every "word x" should listed list item in list view
now wanted set model. model need "field names", in case aren't present.
if i'm using following json data:
{ "data": { "blacklist":[ {"name": "word 1"}, {"name": "word 2"}, {"name": "word 3"} ] } } and giving model field named "name", works fine.
but how set scenario, if json values have no keys define in model (as field/fieldnames)?
without knowing want result aught able modify code looking for.
app.js
ext.loader.setconfig({ enabled : true }); ext.application({ name : ('sf' || 'senchafiddle'), models : ['testmodel'], stores : ['testdata'], launch : function() { ext.create('ext.dataview.list', { fullscreen : true, model : 'testmodel', store : 'testdata', itemtpl : "{blacklist}" }); } }); model:
ext.define('sf.model.testmodel', { extend : 'ext.data.model', config : { fields : [{ name : 'blacklist', type : 'string', // **this parse out values of 'blacklist'** convert : function(value, record) { console.log("value: ", value.length); console.log("record: ", record); var returnarr = []; if (value && value.length > 0) { (var i=0; i<value.length; i++) { returnarr[i] = value[i]; } return returnarr; }; return "could not convert"; } }] } }); store:
ext.define('sf.store.testdata', { extend : 'ext.data.store', config : { model : 'sf.model.testmodel', data : [{ "blacklist":[ "word 1", "word 2", "word 2" ] }], } }); please let me know if missed in question,
good luck, brad
Comments
Post a Comment