1

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

I have Store class:

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

and model class:

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

and associated model class:

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

Model that can used in offline:

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

Where default.model.Top25WordOffline is just like default.model.Top25WordRaw.

View that display accurate format:

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.

  • post default.model.OnlineFinal code and store you looping through is default.store.News.. am i right ? – Viswa Aug 22 '13 at 04:52
  • 1
    please check my edited new store, i have post wrong store. –  Aug 22 '13 at 05:09
  • can i see model used in localStore ? – Viswa Aug 22 '13 at 07:30
  • please check my problem.i added new offline storage model. –  Aug 22 '13 at 11:20
  • there seem to be some different spellings of `definition`, `defintion` - did you try and clear those up? What is the actual problem? – Adam Marshall Aug 22 '13 at 11:31
  • i have done, change from defintion to definition, still problem in my head. please check out my problem once again. –  Aug 22 '13 at 12:13
  • 1
    what are the data you want store using Top25WordFinal model – Viswa Aug 22 '13 at 12:17
  • your model design confusing me.. what you trying achieve using that model – Viswa Aug 22 '13 at 12:20
  • please see my JSON, http://alucio.com.np/trunk/dev/sillydic/admin/api/word/my_favourite_words_with_definition/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363 , would you have alternative model class for this? I am trying to get word with defination. –  Aug 22 '13 at 12:27
  • yes, i saw that.. what are data you want to store in online store and what are data you want to store in offline store ? – Viswa Aug 22 '13 at 12:28
  • Everything on online but an offline i want o store word, status, definition, ratings, def_id. but in my code message store in local but not others. –  Aug 22 '13 at 12:33
  • 1
    ok viswa, I hope you can. –  Aug 23 '13 at 03:52
  • Top25Store loaded all data successfully ? – Viswa Aug 23 '13 at 05:48
  • @Viswa, in Top25Store data loaded successfully, where i have done display all data successfully in view. you can see on view. –  Aug 23 '13 at 06:00
  • I have also post pictorial form , would you like to see this: http://stackoverflow.com/questions/18397623/how-to-get-value-form-record-in-sencha-touch –  Aug 23 '13 at 07:55
  • which definition you want to get.. there 5 definition in that json – Viswa Aug 23 '13 at 08:21
  • @Viswa, one word may have multiple definition, i want all definition to store in localstorage. is there any problem for all definition store in localstorage.How much data to be storageable in local storage. –  Aug 23 '13 at 09:08
  • your model code are very strange and i can post code for storing data for online store (better than your way) but i am not sure you can store that must data in localStorage or not. – Viswa Aug 23 '13 at 12:27

1 Answers1

0

Try to change

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

to

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