我與結構的陣列通過陣列和打印循環值
var citizens1 = [{lat:null,lng:null,socialSecurityNumber:null}];
我想用一個循環來打印每個元素的值,但是這並沒有爲我工作:
代碼
function animate(index,d) {
if (d>eol[index]) {
marker[index].setPosition(endLocation[index].latlng);
if(marker[index].getPosition() == endLocation[index].latlng){
console.log('Completed'+' '+index);
}
return;
}
var p = polyline[index].GetPointAtDistance(d);
marker[index].setPosition(p);
updatePoly(index,d);
timerHandle[index] = setTimeout("animate("+index+","+(d+step)+")", tick);
citizens1.push({lat:marker[index].getPosition().lat(),lng:marker[index].getPosition().lng(),socialSecurityNumber:global_citizens[index].socialSecurityNumber});
if(citizens1.length = '500'){
console.log('500 records saved');
window.clearTimeout(timerHandle);
for(var i = 0; i < citizens1.length ; i++){
console.log(citizens1.lat +',' +citizens1.lng+','+citizens1.socialSecurityNumber);
}
citizens1 = [];
}
}
錯誤
TypeError: citizens1[i].lat is undefined
是'name'一個錯字就在這裏,或者在你的真正的程序,以及之後的時期? – kojiro
對不起,這是一個錯字將解決此問題 – devdar
你能顯示你的完整代碼,或者是這樣嗎? –