jQuery loop over JSON result from AJAX Success?(jQuery 循环从 AJAX 成功的 JSON 结果?)
问题描述
在 jQuery AJAX 成功回调中,我想循环遍历对象的结果.这是响应在 Firebug 中的外观示例.
On the jQuery AJAX success callback I want to loop over the results of the object. This is an example of how the response looks in Firebug.
[
{"TEST1":45,"TEST2":23,"TEST3":"DATA1"},
{"TEST1":46,"TEST2":24,"TEST3":"DATA2"},
{"TEST1":47,"TEST2":25,"TEST3":"DATA3"}
]
如何遍历结果以便可以访问每个元素?我尝试过类似下面的方法,但这似乎不起作用.
How can I loop over the results so that I would have access to each of the elements? I have tried something like below but this does not seem to be working.
jQuery.each(data, function(index, itemData) {
// itemData.TEST1
// itemData.TEST2
// itemData.TEST3
});
推荐答案
可以去掉外层循环,将this
替换成data.data
:
you can remove the outer loop and replace this
with data.data
:
$.each(data.data, function(k, v) {
/// do stuff
});
你很亲密:
$.each(data, function() {
$.each(this, function(k, v) {
/// do stuff
});
});
您有一个对象/映射数组,因此外部循环会遍历这些对象/映射.内部循环遍历每个对象元素的属性.
You have an array of objects/maps so the outer loop iterates over those. The inner loop iterates over the properties on each object element.
这篇关于jQuery 循环从 AJAX 成功的 JSON 结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery 循环从 AJAX 成功的 JSON 结果?


- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01