Google Chrome应用:chrome.storage.local

时间:2013-09-10 16:08:39

标签: javascript json google-chrome-app

我正在努力找出为什么在我正在开发的应用程序中发生以下情况:

所以我读了一个JSON文件,我想阅读并将他的内容保存在localStorage上,在chrome应用程序中是chrome.storage.local

所以我从json文件中得到以下内容:

{
  "schedule": {
    "id": "416a18d6-7e42-4f8a-ac24-e902abe76f39",
    "name": "blabla",
    "updatedOn": "2013-09-08T16:34:41.000Z",
    "etag": "esxrdctfvygbuhnij5464df7g8hu",
    "applications": [
      {
        "id": "app001",
        "type": "text/html",
        "src": "http://www.google.com"
      },
      {
        "id": "app002",
        "type": "text/html",
        "src": "http://www.stackoverflow.com"
      }
    ],
    "normalContent": [
      {
        "layout_id": "layout001",
        "layout_name": "layout1",
        "layout_dur": "indefinite",
        "regions": [
          {
            "region_id": "region001",
            "region_name": "regiao1",
            "left": "0",
            "top": "0",
            "width": "0.5",
            "height": "1",
            "minWidth": "0",
            "minHeight": "0",
            "scheduleItem": "container",
            "limitCycle": "1",
            "selector": "seq",
            "containerList": [
              {
                "cid": "app001",
                "dur": "25"
              },
              {
                "cid": "app002",
                "dur": "15"
              }
            ]
          },
          {
            "region_id": "region002",
            "region_name": "regiao2",
            "left": "0.5",
            "top": "0",
            "width": "0.5",
            "height": "1",
            "minWidth": "0",
            "minHeight": "0",
            "scheduleItem": "container",
            "limitCycle": "1",
            "selector": "seq",
            "containerList": [
              {
                "cid": "app002",
                "dur": "15"
              },
              {
                "cid": "app001",
                "dur": "15"
              }
            ]
          }
        ]
      }
    ]
  }
}

所以我得到了这个,然后我使用以下内容将内容保存在存储中

chrome.storage.local.set({playerSchedule:this.schedule}, function(){
    console.log('saved!')       
});

稍后当我阅读使用以下内容存储的内容时

chrome.storage.local.get(["playerSchedule", "playerScheduleType"], function (res) {
    self.currentSchedule = res.playerSchedule;
    self.scheduleType = res.playerScheduleType;
});

这就是我得到的:

{
  "schedule": {
    "applications": [
      {
        "id": "app001",
        "type": "text/html",
        "src": "http://www.google.com"
      },
      {
        "id": "app002",
        "type": "text/html",
        "src": "http://www.stackoverflow.com"
      }
    ],
    "etag": "esxrdctfvygbuhnij5464df7g8hu",
    "id": "416a18d6-7e42-4f8a-ac24-e902abe76f39",
    "name": "blabla",
    "normalContent": [
      {
        "layout_dur": "indefinite",
        "layout_id": "layout001",
        "layout_name": "layout1",       
        "regions": [
          {
            ...
            "containerList": [
            ]
          },
          {
            ...
            "containerList": [
            ]
          }
        ]
      }
    ],
    "updatedOn": "2013-09-08T16:34:41.000Z"    
  }
}

正如您所看到的,我读取的内容按字母顺序排列,而containerList中的内容为空。出现这种情况的原因是什么?我通过将对象转换为字符串并将其存储来解决这个问题,但我想知道为什么保存为对象我从阅读作为对象得到的还是我缺少的东西?

提前致谢。

1 个答案:

答案 0 :(得分:1)

这可能是http://code.google.com/p/chromium/issues/detail?id=277647。修补程序适用于Chrome 31。

相关问题