我不知道如何chrome.storage.local
在 javascript 中删除值?
我是这样使用的,但存储值没有从商店中删除: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;
}
注意:您不能删除值,您可以删除具有特定名称的索引,是什么原因导致它们被删除的值。
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);
});
});
});
});
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句