gpt4 book ai didi

javascript - 无法访问 $.each 中的对象属性

转载 作者:行者123 更新时间:2023-11-28 18:57:58 25 4
gpt4 key购买 nike

在返回一个对象的ajax请求之后,我执行$.each,因为我需要读取返回的所有对象(约会)。但似乎在 $.each 中该对象未定义,我不知道为什么。这是我的每个请求的代码:

$.each(response.appointments, function(index, appointment)
{
var event =
{
'id': appointment['id'],
'title': appointment['service']['name'] + ' - '
+ appointment['customer']['first_name'] + ' '
+ appointment['customer']['last_name'],
'start': appointment['start_datetime'],
'end': appointment['end_datetime'],
'allDay': false,
'color': '#' + appointment['res_id']['hex_color'],
'data': appointment
};
calendarEvents.push(event);
});

这是console.log(response)中返回的response对象的内容:

enter image description here

任命结构:

enter image description here

有人有办法解决这个问题吗?

最佳答案

如果我正确读取了您的对象图片(请下次包含实际文本),响应 是一个对象数组,每个对象包含约会。在这种情况下,您会想说:

$.each(response, function(index, rsp) {
$.each(rsp.appointments, function(index, appointment)
{
var event =
{
'id': appointment['id'],
'title': appointment['service']['name'] + ' - '
+ appointment['customer']['first_name'] + ' '
+ appointment['customer']['last_name'],
'start': appointment['start_datetime'],
'end': appointment['end_datetime'],
'allDay': false,
'color': '#' + appointment['res_id']['hex_color'],
'data': appointment
};
calendarEvents.push(event);
})
});

关于javascript - 无法访问 $.each 中的对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33241477/

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