本地存储与json和hasmany

时间:2012-01-27 08:41:25

标签: json sencha-touch local-storage

我在chrome上使用sencha touch 1.1.0和我的故事:

我从服务器获得了json响应,并将其存储在localstorage中。

这里是我的责任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"}]}]})

如你所见,有二维'数组'。有几本杂志,每本杂志都有几篇文章。

这是我的模特

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'
});

这是我的localstorage商店

offlinestore = new Ext.data.Store({
model: 'magazines',
autoLoad: true,
getGroupString : function(record) {
return record.get('titre');
},
proxy: {
type: 'localstorage',
id:'magazines_id'
},

}
});

这是我的商店谁在本地存储中执行请求和加载数据

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();

}
}
});

以及我如何尝试显示所有结果:

var tpl = new Ext.XTemplate(
'<table width="97%" border="0" cellspacing="0" cellpadding="0" style="margin:0 auto;">',
'<tpl for=".">',
'<tr class="headerNumero">',
'<td colspan="3"><div style="width:120px;float:right;"><div style="border:1px solid #CCC;background:red;width:102px;height:34px;"></div></div><h1>#{numero} <span class="discret">{titreLong} {titre}{[xindex % 3 === 0 ? "even" : "odd"]}</span></h1></td>',
'</tr>',
'<tr class="rubriques">',
//'<tpl for="articles">',
// '<td><div class="commentaires"><span>1</span><h3>DŽcouverte</h3></div></td>',
//'<tpl>',
'</tr>',
'</tpl>',
'</table>'


&nbsp;

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'
}]
});

结果是:

我获得杂志的所有头衔,但localStorage中没有文章记录。 我想要 : 如何将“文章”数据存储到localstorage? 如何从“localstorage”获取“文章”数据?

问候

很少(或没有)更多信息,我在控制台中收到了这条消息:

sencha-touch-debug.js:13028
Uncaught TypeError: Cannot read property 'parentNode' of undefined

0 个答案:

没有答案