chrome.storage.sync.remove array doesn't work

五迷三道 提交于 2019-12-03 16:24:33

When you pass in a string to sync.remove, Chrome will attempt to remove the one single item whose key matches the input string. If you need to remove multiple items, use an array of key values.

Also, you should move your remove call to inside your get callback.

function clearNotes(symbol)
{
// CHANGE: array, not a string
var toRemove = [];

chrome.storage.sync.get( function(Items) {
    $.each(Items, function(index, value)
    {
        // CHANGE: add key to array
        toRemove.push(index);         
    });

    alert(toRemove);

    // CHANGE: now inside callback
    chrome.storage.sync.remove(toRemove, function(Items) {
        alert("removed");

        chrome.storage.sync.get( function(Items) {
            $.each(Items, function(index, value)
            {
                alert(index);           
            });
        });
    }); 
});

}; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!