Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

javascript - how to remove data from a object using chrome storage?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...