如何删除chrome.storage.local

时间:2018-03-07 13:14:20

标签: javascript jquery google-chrome-extension

我没有了解如何删除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;
}

1 个答案:

答案 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);
        });
      });
    });
  });
};