【问题标题】:how to remove data from a object using chrome storage?如何使用 chrome 存储从对象中删除数据?
【发布时间】:2015-03-09 22:04:10
【问题描述】:

我有一个对象存储在 chrome 存储中,如下所示:

{
    "planA": 
    {
        123: {key: 'some key'}
        124: {key: 'some other key'}
    },
    "planB": 
    {
        223: {key: 'some key'}
        234: {key: 'some other key'}
    }
}

我想做chrome.storage.sync.remove([{"planA": "123"}]);之类的事情

但这似乎不起作用Error in response to storage.get: Error: Invalid value for argument 1. Value does not match any valid type choices.

来自documentationStorageArea.remove(string or array of string keys, function callback)

蚂蚁的想法?

【问题讨论】:

  • 它似乎期望string or array of string 作为参数。你的第一个数组元素是一个对象。

标签: javascript google-chrome-extension storage google-chrome-storage


【解决方案1】:

您无法在单个 API 调用中做到这一点。 API 仅提供对顶级密钥的访问权限:您可以整体获取或设置 planA

因此,您需要编写自己的 get/set 函数,检索所需的顶级键,根据需要修改对象,然后将其保存回来。

【讨论】:

  • 是的,我要去get 然后删除子对象并重新保存:)
猜你喜欢
  • 1970-01-01
  • 2021-04-03
  • 2019-05-16
  • 1970-01-01
  • 2019-08-05
  • 1970-01-01
  • 2021-09-08
  • 1970-01-01
相关资源
最近更新 更多