无法在Sencha Touch中的本地存储上设置嵌套的JSON数据 [英] Unable setting nested json data on localstorage in sencha touch

查看:61
本文介绍了无法在Sencha Touch中的本地存储上设置嵌套的JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sencha中的本地存储上设置嵌套json数据时遇到问题.

I have problem to setting nested json data on localstorage in sencha.

我有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>'
        ),

我看到了有价值的东西.但是在本地存储中存在问题:在控制器中,

I got value on view. but Problem to store in localstorage: in controller,

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

我已经设置了有关本地存储和静态评级的消息,但定义上存在问题.如何存储定义,请清除.

I have set message on localstorage and static ratings but problem in definition. How to store definitions, please clearfy.

推荐答案

尝试更改

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

这篇关于无法在Sencha Touch中的本地存储上设置嵌套的JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆