我是一個新的jquery學習者。我有個問題。關於jquery關聯數組我應該怎麼做?
我寫了這個腳本,但結果不正確。
var details = <?php echo json_encode($all_data["holiday"]);?>;
var myArray = details.split("|");
var a = {};
var natDays = [];
for(var i=0;i<myArray.length;i++){
var ex_array = myArray[i].split(",");
a["month"] = ex_array[0];
a["date"] = ex_array[1];
a["name"] = ex_array[2];
natDays.push(a);
}
alert(JSON.stringify(natDays));
我得到以下不正確的結果在警報:
[
{"month":"3","date":"7","name":"test"},
{"month":"3","date":"7","name":"test"},
{"month":"3","date":"7","name":"test"},
{"month":"3","date":"7","name":"test"}
]
它應該是:
[
{"month":"4","date":"11","name":"test"},
{"month":"4","date":"4","name":"test"},
{"month":"4","date":"13","name":"song kran festival"},
{"month":"3","date":"7","name":"test"}
]
我該怎麼辦?請指教。
請顯示'$ all_data [「假期」]' –