gpt4 book ai didi

javascript - 如何在字典中循环遍历字典列表并获取其中的值 - Javascript,用于 django 中的 ajax 调用

转载 作者:行者123 更新时间:2023-12-03 05:36:18 26 4
gpt4 key购买 nike

我有一个 list

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 和字典的内容,但我无法访问循环中所需的字典值。 ?如果有人能给出代码示例,我将非常感激。

谢谢

最佳答案

在循环中,只需将 mylist[i] 更改为 mylist[i][fields'],

for (var i = 0; i < mylist.length; i++) {

$("#posts").prepend( "<div >" +"<h2 class='bg-info text-align-center'> Tasks" +"</h2>"
+ "<strong> Name: " + " " + mylist[i]['fields'].name + "</strong>"
+ "<strong> Task: " + " " + mylist[i]['fields'].discription + "</strong>"
+ "<strong> Due Date: " + " " + mylist[i]['fields'].dueDate + "</strong>"
+ "<strong> Mins before due: " + " " + mylist[i]['fields'].dueMinutes + "</strong>"
+ "<strong> TimeZone: " + " " + mylist[i]['fields'].timezoneChoice + "</strong>"
+ "<hr>" +"</div>")
}

关于javascript - 如何在字典中循环遍历字典列表并获取其中的值 - Javascript,用于 django 中的 ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40722900/

26 4 0
文章推荐: javascript - 来自 fiori 应用程序模板时将 ui5 应用程序部署到启动板
文章推荐: javascript - React 渲染函数阻止每次调用时创建新的 Canvas 元素 - Charts.js
文章推荐: javascript - 测试/检查变量的限制是什么?
文章推荐: javascript - AngularJS 用