Trying to pass values to local storage using Sencha Touch 2.1.1

こ雲淡風輕ζ 提交于 2019-12-24 13:34:02

问题


Can anyone tell me why this bit of code doesn't create an entry into localstorage?

    myLocalStore.load();

    var now = new Date();
    var cardId = (now.getTime()).toString() + (this.getRandomInt(0, 100)).toString();

    var entry1 = { id: cardId, dateCreated: now, title: 'The Title', narrative: 'the Text' };
    var newRecord = new PinYin.model.Default(entry1);
    myLocalStore.add(newRecord);

    myLocalStore.sync();

    console.log(entry1);

The console outputs

Object{id: "136575772251069", dateCreated: Fri Apr 12 2013 17:08:42 GMT+0800 (Taipei Standard Time), title: "The Title", narrative: "the Text"}

which is the correct format so im not sure what I'm doing wrong...

if I replace myLocalStore.add(entry1); with myLocalStore.add('value');

then i'll get the following inputted into the local storage

{"id":"ext-record-1","dateCreated":null,"title":null,"narrative":null}


回答1:


I faced the same situation and found the solution like that,

First of all, if you set "idProperty" field of model, remove it.

After that, use the following convention.

myOfflineStore.add([{ listItemId: record.data.listItemId, 
                      listItemTitle: record.data.listItemTitle, 
                      listItemImageCode: record.data.listItemImageCode,     
                      listItemNewPostCount: record.data.listItemNewPostCount }]);

Using [, ] is the key point.

EDIT: If you want to use idProperty, then you need to set the newly added record as "phantom" with setting phantom = true




回答2:


Try like this...

      var airline_name = res[i].AirLineName; 
localStorage.setItem("AirlineCode3two",record.get('AirlineCode32'));

        var stored_locally2 = {'ID2': i,'AirLineName2': res[i].AirLineName,};

             //Adding our array to LocalStore(localStorage)
                         var localstore2 = Ext.getStore('TwowayStorage');

                         var twowayc1=localstore2.getCount();
                         localstore2.add(stored_locally2);
                         localstore2.sync();
                         localstore2.load();


来源:https://stackoverflow.com/questions/15967990/trying-to-pass-values-to-local-storage-using-sencha-touch-2-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!