gpt4 book ai didi

jQuery、JSON 数组推送

转载 作者:行者123 更新时间:2023-12-01 06:44:06 25 4
gpt4 key购买 nike

我在完成这项工作时遇到了一些问题:

这是我通过 ajax 拉取的 json 数组:

{
"message": [{
"title": "Account",
"id": 1
}, {
"title": "Content",
"id": 2
}, {
"title": "Other",
"id": 3
}]
}

这里是 JavaScript:

var items = [];
$.get("settings.php", {
getlink: 1,
}, function(json) {
$.each(json.message, function() {
items.push(this);
});

},"json");

console.log(items)

但由于某种原因 items 数组始终为空 []我可以在 firebug 中看到 json 返回的数组,但我无法推送它。

最佳答案

使用 $.each索引、值 返回:

$.each(json.message, function(index, value) {
items.push(value);
});

注意: $.each() .each() 不同

希望这有帮助。

关于jQuery、JSON 数组推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40855011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com