1

谁能告诉我为什么这段代码不会创建本地存储的条目?

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

控制台输出

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

这是正确的格式,所以我不确定我做错了什么......

如果我替换 myLocalStore.add(entry1); 与 myLocalStore.add('value');

然后我将以下输入到本地存储中

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

4

2 回答 2

0

试试这样...

      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();
于 2013-04-20T04:30:41.750 回答
0

我遇到了同样的情况并找到了这样的解决方案,

首先,如果您设置模型的“idProperty”字段,请将其删除。

之后,使用以下约定。

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

使用 [, ] 是关键点。

编辑:如果要使用 idProperty,则需要将新添加的记录设置为“幻像”,并设置幻像 = true

于 2013-04-16T11:28:04.560 回答