如何使用Chrome存储从对象中删除数据? [英] how to remove data from a object using chrome storage?

查看:578
本文介绍了如何使用Chrome存储从对象中删除数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  {
planA:
{
123:{key:'一些关键'}
124:{key:'其他关键'}
},
planB:
{
223:{key:'某个关键'}
234:{key:'其他关键'}
}
}

我想要做一些类似于 chrome.storage.sync.remove([{planA:123} ]);



但似乎不起作用响应storage.get时出错:错误:参数1.值与任何有效的类型选择不匹配。



来自 documentation StorageArea.remove(字符串或字符串键数组,函数回调)



蚂蚁的想法?

解决方案

你不能在单个API调用中做到这一点。 API只允许访问顶级密钥:您可以获取或设置 planA 作为一个整体。



您需要编写自己的get / set函数,检索所需的顶级密钥,根据需要修改对象并将其保存回去。


i have an object stored inside chrome storage that looks like this:

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

i want to do something like chrome.storage.sync.remove([{"planA": "123"}]);

but that seems not to work Error in response to storage.get: Error: Invalid value for argument 1. Value does not match any valid type choices.

from the documentation StorageArea.remove(string or array of string keys, function callback)

ant ideas?

解决方案

You can't do that in a single API call. The API only gives access to top-level keys: you can get or set planA as a whole.

So you'll need to write your own get/set functions, that retrieve the required top-level key, modify the object as required, and save it back.

这篇关于如何使用Chrome存储从对象中删除数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆