【发布时间】:2023-03-03 15:45:01
【问题描述】:
我在另一个 SO 帖子中看到了这段代码:jQuery UI Autocomplete with ASP MVC
$("#CustomerID").autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
url: "/customer/search",
dataType: "json",
data: {
term: request.term
},
error: function(xhr, textStatus, errorThrown) {
alert('Error: ' + xhr.responseText);
},
success: function(data) {
response($.map(data, function(c) {
return {
label: c.Company,
value: c.ID
}
}));
}
});
},
minLength: 2,
select: function(event, ui) {
alert('Select');
}
});
除了成功函数,我什么都懂。我知道 map 正在获取一个数组并将每个值映射到一个具有 label 和 value 属性的新对象并返回新数组,但我不确定 response() 的作用。
【问题讨论】:
标签: javascript jquery response