我有存儲在本地存儲中的數據,我想將它拉入數組中。但沒有成功...... 正如您將在下面的代碼中看到的,我想CONSOLE.LOG數組,但它給我寫信:JQuery和Phonegap從本地存儲陣列中保存數據
(瀏覽器控制檯)
Uncaught SyntaxError: Unexpected end of input index.html:204 (anonymous function) index.html:204 e.resolveWith jquery-1.6.min.js:16
e.extend.ready jquery-1.6.min.js:16 c.addEventListener.z jquery-1.6.min.js:16
cordova :: fired deviceready event! ripple.js:37
8 canvas not found!
這是我的本地存儲: 這是代碼:
$(function() {
window.localStorage.setItem('Sample block', '{"time":1383107260539,"counter":5}');
track_items_for_chart = [];
for (i = 0; i < window.localStorage.length; i++) {
var key_name = (window.localStorage).key(i);
var time = (window.localStorage.getItem(key_name));
time = (JSON.parse(time)).time;
var counter = jQuery.parseJSON(window.localStorage.getItem(key_name)).counter;
counter = JSON.parse(counter);
track_items_for_chart.push("{ date: " + time + ", km: " + counter + "},");
}
console.log(track_items_for_chart);
});
控制檯錯誤並沒有涉及到上面的代碼... –