如何使用 chrome 存储从对象中删除数据?
how to remove data from a object using chrome storage?
我在 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.
来自 documentation StorageArea.remove(string or array of string keys, function callback)
蚂蚁想法?
您不能在单个 API 调用中完成此操作。 API 仅允许访问顶级键:您可以整体获取或设置 planA
。
因此您需要编写自己的 get/set 函数,检索所需的顶级键,根据需要修改对象,然后将其保存回来。
我在 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.
来自 documentation StorageArea.remove(string or array of string keys, function callback)
蚂蚁想法?
您不能在单个 API 调用中完成此操作。 API 仅允许访问顶级键:您可以整体获取或设置 planA
。
因此您需要编写自己的 get/set 函数,检索所需的顶级键,根据需要修改对象,然后将其保存回来。