gpt4 book ai didi

javascript - 如何命名返回数组?

转载 作者:行者123 更新时间:2023-11-28 21:05:28 24 4
gpt4 key购买 nike

不太确定我这样做是否正确。它看起来比实际需要的更复杂一些。但我正在尝试从 json 数组中提取特定的数据。我需要这个数据 block 的几个特征,然后我需要获取return,标记return,并将其传递给成功调用底部的方法。

$(document).ready(function() {
if ( window.location.href.match(/customer_number/).length > 0) {

$customer_id = window.location.href.split(/customer_number=/)[1];

$.ajax({
url: '/customers/filter.json',
data: { id: $customer_id },
dataType: 'json',
success: function(data) {
response($.map(data, function(row) {
return {
value: row.customer.name,
customer_number: row.customer.customer_number,
id: row.customer.id,
name: row.customer.name,
phone_number: row.customer.phone_number,
email: row.customer.email,
service_address: row.customer.service_address,
service_city: row.customer.service_city,
service_state: row.customer.service_state,
service_zip_code: row.customer.service_zip_code,
billing_adress: row.customer.billing_address,
billing_city: row.customer.billing_city,
billing_state: row.customer.billing_state,
billing_zip_code: row.customer.billing_zip_code,
primary_contact_name: row.customer.primary_contact ? row.customer.primary_contact.first_name + ' ' + row.customer.primary_contact.last_name : ''
};
render_customer(name_of_return);
// ^^ Not sure how to label that return into an object.
}));
}
});
};
});

最佳答案

您将返回的对象传递回 $.map 处理迭代函数的返回值(它在数组中构建这些值),然后将该数组传递给您的响应函数。在 JavaScript 中,当您调用函数(或返回一个值)时,您不会给出参数/返回值名称。在争论的情况下,它完全是位置性的。 (函数定义可能会为它们分配名称,但在调用它们时却不会。)对于返回值,只有一个。

关于javascript - 如何命名返回数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9991131/

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