简体   繁体   English

Google Chrome应用程式:chrome.storage.local

[英]Google Chrome Apps: chrome.storage.local

I am having a struggle finding out why the following is happening in a application i'm developing: 我正在努力找出为什么我正在开发的应用程序中发生以下情况:

So i read a JSON file where i want to read and save his content on localStorage, which in a chrome app is chrome.storage.local 所以我读了一个JSON文件,我想在其中读取内容并将其保存在localStorage上,在chrome应用程序中是chrome.storage.local

So i get the following from a json file: 所以我从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"
              }
            ]
          }
        ]
      }
    ]
  }
}

So i get this and then i save the content in storage using: 所以我得到了,然后我使用以下方法将内容保存在存储中:

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

Later on when i read the content stored using: 稍后,当我读取使用以下内容存储的内容时:

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

This is what i get: 这就是我得到的:

{
  "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"    
  }
}

As you can observe, the content i read comes in alphabetic order and the content in containerList is empty. 如您所见,我读取的内容按字母顺序排列,containerList中的内容为空。 Any reason why this is happening? 为什么会这样呢? I solved this by converting the object to string and storing it, but i wonder why saving as object i get that from reading as an object or is there something i am missing? 我通过将对象转换为字符串并将其存储来解决此问题,但我想知道为什么将另存为对象时从读取为对象时得到了该信息,或者我缺少什么?

Thanks in advance. 提前致谢。

This is probably http://code.google.com/p/chromium/issues/detail?id=277647 . 这可能是http://code.google.com/p/chromium/issues/detail?id=277647 Fix is in the works for Chrome 31. 已修复Chrome 31的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM