无法在sencha touch中设置localstorage上的嵌套json数据

时间:2013-08-22 03:54:53

标签: sencha-touch sencha-touch-2 local-storage

我在sencha中的localstorage上设置嵌套的json数据时遇到问题。

我有Store类:

 Ext.define('default.store.Top25Store',{
extend: 'Ext.data.Store', 
config:
{
    autoLoad:true,
    model: 'default.model.Top25WordFinal',    
    id:'TodaysWord',
    proxy:
    {
        type: 'ajax',
        url: 'http://alucio.com.np/trunk/dev/sillydic/admin/api/word/my_favourite_words_with_definition/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363', 
        reader:
        {
                type:'json',
                rootProperty:''
        }
    }
}
});

和模型类:

Ext.define('default.model.Top25WordFinal', {
    extend: 'Ext.data.Model',

    requires: ['default.model.Top25WordRaw'],

    config: {
        fields: [
            {name: 'status', mapping: 'status'},
            {name: 'message', mapping: 'message'},
            {name: 'name', mapping: 'name'},
            {name:'data', mapping: 'data'},
            {name: 'definition', mapping: 'definitions.definition'},
            {name: 'ratings', mapping: 'definitions.rating'},
            {name:'def_id', mapping:'definitions.def_id'},
        ],
    }
});

和相关的模型类:

Ext.define('default.model.Top25WordRaw', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
        'name',
        'author',
        'word_id',
        'category',
        'definition',
        'rating',
        'def_id',
        'example',
        'author',
        'is_favourite'
        ],
        belongsTo: "default.model.Top25WordFinal"
    }
});

可在离线状态下使用的模型:

Ext.define('default.model.Top25WordRawOffline', {
    extend: 'Ext.data.Model',

    requires: ['default.model.Top25WordOffline'],

    config: {
        fields: [
            {name: 'status', mapping: 'status'},
            {name: 'message', mapping: 'message'},
            {name: 'name', mapping: 'name'},
            {name:'data', mapping: 'data'},
            {name: 'definition', mapping: 'definitions.definition'},
            {name: 'ratings', mapping: 'definitions.rating'},
            {name:'def_id', mapping:'definitions.def_id'},
        ],
        identifier:'uuid', // IMPORTANT, needed to avoid console warnings!
    proxy: {
      type: 'localstorage',
      id  : 'Top25Display'
    }
    }
});

default.model.Top25WordOffline 就像 default.model.Top25WordRaw

查看显示准确格式:

store: 'Top25Store',
       itemTpl: new Ext.XTemplate(
           '<div>',                
           '<tpl for="data">',
           '<ul class="parabox">',
           '<li><h2 ><b>{name}</b> </h2>',                          
           '<tpl for="definitions">',
           '<ul class="para-box-wrapper">',
           '<li class="{rating}"><div id = "definition" class="{rating}">','{definition}',
           '<span class="authorBox"><i>Author: {author}</i></span>',
           '<div id = "favourite" class="{is_favourite}" ></div>',
           '</li>' ,
        '</div>',
        '</ul></li>', 
        '</tpl>',
        '</ul>',
        '</tpl>',
        '</div>'
        ),

我对观点有价值。但存储在localstorage中的问题:在控制器中,

localStore.getProxy().clear();
         store.each(function(record) {
         var rec = {
         message : record.data.message,
         definition : record.data.definitions.definition,
         ratings:"red"
         // defintion:record.data.definitions.def_id
        };

        localStore.add(rec);
        localStore.sync();

我已在localstorage和静态评级上设置了消息,但在定义方面存在问题。如何存储定义,请清除。

1 个答案:

答案 0 :(得分:0)

尝试更改

var rec = {
         message : record.data.message,
         definition : record.data.definitions.definition,
         ratings:"red"
         // defintion:record.data.definitions.def_id
        };

var rec = Ext.create('default.model.Top25WordOffline', 
         {
             message : record.data.message,
             definition : record.data.definitions.definition,
             ratings:"red"
         });