我没有了解如何删除javascript中的chrome.storage.local
值?
我使用这样但存储值不会从商店中删除:chrome.storage.local.remove(result.MyFile.Base64File);
请检查以下代码,此处我使用 chrome.storage.local.set 设置
var obj = { DocName: "name", Base64File: "Base64string" };
chrome.storage.local.set({ 'MyFile': obj });
和chrome.storage.local.get来检索值
chrome.storage.local.get('MyFile', function (result) {
var PdfBase64 = result.MyFile.Base64File;
var DocumentName = result.MyFile.DocName;
}
答案 0 :(得分:0)
注意:您无法删除值,您可以删除具有特定名称的索引,这些索引会导致它们被删除。
Tbh我无法运行代码,但我很确定这样的东西应该可行。但我真的建议你避免使用chrome.storage因为它是某种“哑”:)
所以请看一下这段代码:
function clearItem(symbol) {
var remove = [];
chrome.storage.sync.get(function(Items) {
$.each(Items, function(index, value) {
if (index == "symbol") remove.push(index);
});
chrome.storage.sync.remove(remove, function(Items) {
chrome.storage.sync.get(function(Items) {
$.each(Items, function(index, value) {
console.log("removed: " + index);
});
});
});
});
};