首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌Chrome应用: chrome.storage.local

谷歌Chrome应用: chrome.storage.local
EN

Stack Overflow用户
提问于 2013-09-11 00:08:39
回答 1查看 402关注 0票数 0

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

因此,我读取了一个JSON文件,希望在其中读取并保存他在localStorage上的内容,在chrome应用程序中,它是chrome.storage.local

因此,我从一个json文件中获得了以下内容:

代码语言:javascript
复制
{
  "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"
              }
            ]
          }
        ]
      }
    ]
  }
}

因此,我得到了这个,然后我使用以下命令将内容保存在存储中:

代码语言:javascript
复制
chrome.storage.local.set({playerSchedule:this.schedule}, function(){
    console.log('saved!')       
});

稍后,当我使用以下命令读取存储的内容时:

代码语言:javascript
复制
chrome.storage.local.get(["playerSchedule", "playerScheduleType"], function (res) {
    self.currentSchedule = res.playerSchedule;
    self.scheduleType = res.playerScheduleType;
});

这是我得到的:

代码语言:javascript
复制
{
  "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中的内容是空的。为什么会发生这种情况呢?我通过将对象转换为字符串并将其存储来解决了这个问题,但我想知道为什么将对象另存为对象时,我会将其作为对象读取,或者是我遗漏了什么?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-09-12 00:42:01

这可能是http://code.google.com/p/chromium/issues/detail?id=277647。Chrome 31的修复工作正在进行中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18723922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档