有如何通過與字典詞典列表循環和內獲取值 - 我的Javascript,爲Ajax調用在Django
mylist = [{"model": "todolist.todolist", "pk": 1, "fields": {"timezoneChoice": "Africa/Johannesburg", "user": 44, "name": "ergdsg", "discription": "dsgdsg", "dueMinutes": -61504892, "emailSent": false, "dueDate": "1899-12-11T08:20:00Z", "create_at": "2016-11-21T04:37:29.253Z"}}, {"model": "todolist.todolist", "pk": 2, "fields": {"timezoneChoice": "Africa/Johannesburg", "user": 44, "name": "ergdsg", "discription": "dsgdsg", "dueMinutes": -61504892, "emailSent": false, "dueDate": "1899-12-11T08:20:00Z", "create_at": "2016-11-21T04:38:12.525Z"}}]
我試圖從獲得的價值列表中的「字段「和他們的鍵
for (var i = 0; i < mylist.length; i++) {
$("#posts").prepend("<div >" +"<h2 class='bg-info text-align-center'> Tasks" +"</h2>"
+ "<strong> Name: " + " " + mylist[i].name + "</strong>"
+ "<strong> Task: " + " " + mylist[i].discription + "</strong>"
+ "<strong> Due Date: " + " " + mylist[i].dueDate + "</strong>"
+ "<strong> Mins before due: " + " " + mylist[i].dueMinutes + "</strong>"
+ "<strong> TimeZone: " + " " + mylist[i].timezoneChoice + "</strong>"
+ "<hr>" +"</div>")
},
我該怎麼做。請我真的需要幫助,一直在掙扎。我已經閱讀了JavaScript和字典,但是我無法訪問循環中所需的字典值。 ?如果有人能給出一個代碼示例,我將不勝感激。
謝謝
什麼是錯誤 – Mahi
@Mahi,我只是沒有得到價值,它說undefined –
看到jkong的答案。它會工作 – Mahi