localstorage with json and hasmany

I work with sencha touch 1.1.0 on chrome and this my story : I get a json response from a server, and I store it in a localstorage. here my respons Json stcCallback1001({"success":true, "magazines":[ {"magazine_id":"9","numero":1,"titre":"bla bla bla bla","articles":[{"article_id":1,"titre":"bee or not to bee"},{"article_id":2,"titre":"the sky is blue"}]}, {"magazine_id":"10","numero":12,"titre":"bli bli bli","articles":[{"article_id":1,"titre":"where is brian"},{"article_id":2,"titre":"do you want a cup of tea"}]}]}) as you can see, there are two dimensional 'array'. There several magazines, and in each magazine there several articles. Here my model new Ext.regModel('magazines',{ fields : [ {name : 'magazine_id', type :'int'}, {name : 'numero', type:'int'}, {name : 'titreLong' , type : 'string'} ], idProperty : 'magazine_id', //ClŽ primaire de la table, hasMany:{ model:'articles', name:'articles' } }); new Ext.regModel('articles',{ fields : [ {name : 'magazine_id', type :'int'}, {name : 'article_id', type :'int'}, {name : 'titre' , type : 'string'}, {name : 'Mimage', type :'string'}, {name : 'datePublicationFormat', type : 'string'} ], idProperty : 'article_id', //ClŽ primaire de la table belongsTo: 'magazines' }); here my localstorage store offlinestore = new Ext.data.Store({ model: 'magazines', autoLoad: true, getGroupString : function(record) { return record.get('titre'); }, proxy: { type: 'localstorage', id:'magazines_id' }, } }); here my store who do the request and load datas in local storage var articleStoreDist = new Ext.data.Store({ model:'magazines', proxy : { type: 'scripttag', url :'http://webservive_to_call', reader : { type:'json', root:'magazines' } }, autoLoad:true, listeners : { load: function(){ offlinestore.getProxy().clear(); offlinestore.data.clear(); offlinestore.sync(); articleStoreDist.each(function(record,index){ offlinestore.add(record.copy()); }); offlinestore.sync(); offlinestore.load(); } } }); and how I try to show all results : var tpl = new Ext.XTemplate( '', '', '', '', '', '', //'', // '', //'', '', '', '

#{numero} {titreLong} {titre}{[xindex % 3 === 0 ? "even" : "odd"]}

1

DŽcouverte

' home = new Ext.Panel({ //style:'background:#EFEEE7', fullscreen:true, layout:'fit', items: [{ xtype: 'dataview', autoHeight:true, multiSelect: true, store: offlinestore, tpl:tpl, itemSelector:'div.tpl' }] }); The result is : I get all title of magazine, but there are no article record in localStorage. I would like : How store "article" data to localstorage? How get "article" data frome localstorage? regards Little (or not) more information, I got this message in console : sencha-touch-debug.js:13028 Uncaught TypeError: Cannot read property 'parentNode' of undefined

以上就是localstorage with json and hasmany的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏