我正在尝试将testList
作为元素添加到holdTestList
数组中。
当前,由于sync.set
每次都会覆盖变量,但是我试图通过声明新列表holdTestList
并推送通过sync.get
获得的列表来存储所有变量({testList
)上
SettingScript.js
testList.push(var1, var2, var3);
chrome.storage.sync.set({
list: testList,
}, function() {
console.log("added to list");
});
GettingScript.js
window.addEventListener('load', getContents);
var holdTestList = []; // THIS ARRAY IS USED TO STORE THE ORIGINAL LIST AND THE NEW LISTS ADDED TO IT
function getContents() {
chrome.storage.sync.get({
list: []
},
function(data) {
console.log(data.list);
holdTestList.push(data.list); // Putting the new variables into the full array
});
}