我檢索localStorage與每個循環的數據,但現在我需要一個for循環,這使得相同的事情。localStorage each和for循環
所以我每次循環的樣子:
var alleDaten = $.parseJSON(localStorage.getItem("Deneme"));
$.each(alleDaten, function(i,item){
alert(item.id);
alert(item.createdBy);
});
我試過這個代碼,但它不工作:
var alleDaten = $.parseJSON(localStorage.getItem("Deneme"));
for (i=0;i < alleDaten.length;i++) {
var x= localStorage.getItem(localStorage.key(i));
alert(x[i].id);
alert(x[i].createdBy);
}
你能在一個轉換的循環? 在此先感謝
我已經找到了解決辦法:
var alleDaten = $.parseJSON(localStorage.getItem("Deneme"));
for (var i = 0; i < alleDaten.length; i++) {
var x= alleDaten[i].id;
var y= alleDaten[i].createdby;
alert(x);
alert(y);
}
但還是謝謝你
在你使用'$ .parseJSON'函數的第一部分代碼中,是否有一個原因讓你在for循環中不使用它? – Nunners
我也用過第二個代碼。 – aldimeola1122
在循環內部,它應該是'var x = alleDaten [i];' – techfoobar