即時通訊工作在鉻擴展,並與chrome.storage api有問題。我想將一個數組保存到存儲中,數組將被存儲,但不是數組的值。所以array [x]總是'null'。代碼如下所示:Chrome.storage不會存儲陣列正確
var storage = chrome.storage.local;
bookmarks = new Array();
var newButton = document.createElement('input');
//... Button properys are getting set
bookmarks[bookmarks.length] = newButton; //tried it also with .push()
var obj = {};
obj['bookmarks'] = bookmarks;
storage.set(obj, function(){ console.log('bookmark saved'); });
重啓延伸,並通過獲取存儲後:
storage.get(null, function(result){
console.log('Storage: ', result);
});
日誌看起來是這樣的:
Storage:
Object
bookmarks: Array[1]
0: null
length: 1
__proto__: Array[0]
__proto__: Object
任何建議怎麼回事錯誤的,爲什麼數組不正確存儲?
謝謝!
如果你打印newButton變量,你會得到什麼? – Rayf
如果我記錄按鈕我得到: – Scarysize
如果你修復索引,像這樣 - bookmarks [0] = newButton;它仍然存儲空?存儲中的 – Rayf