0

它刚刚工作,现在我无法进入 chrome.storage.local.get() 的回调。

我在本地存储中有数据,并且我已经正确编写了它。

为什么会失败?我是误解了什么还是我错过了什么?

chrome.storage.sync.get("wortlisteOptionId", function(result){
    if(result["wortlisteOptionId"] != "" && result["wortlisteOptionId"] !== undefined){
        var prevSelection = result["wortlisteOptionId"];
    }
    var item = document.getElementById('wortlisten');
    // works till here
    chrome.storage.local.get("wortlisten", function(result)
    {
        let val;
        let optioncollection = "";
        if(result["wortlisten"] != null){
            for(val of result["wortlisten"]){
                optioncollection += '<option value="' + val.id + '">' + val.name + '</option>';                
            }
            item.innerHTML = optioncollection;

            if(prevSelection != null){
                item.selectedIndex = prevSelection;
            }
            restoreLocalData();                
        }
    });
});
4

1 回答 1

0

我不确定是什么导致了这个问题。我最好的猜测是,我在本地机器上使用 xampp 对其进行了测试,但性能非常糟糕。在我用我的生产环境测试它之后,我没有遇到这个问题......

在我的路上,我还发现这个页面有一些解释:Returning Chrome storage API value without function

于 2020-06-05T06:44:06.453 回答