【发布时间】:2011-12-30 12:36:39
【问题描述】:
我正在为不同的字段使用 JQuery UI 自动完成功能。为了获取数据,我使用函数作为源。它工作得很好! 我想知道是否有一种方法不在源代码中使用匿名函数,而是声明一个通用函数,该函数将有一个参数来重定向到正确的 URL。 我是 JS 和 JQuery 的新手,所以我不知道参数 request 和 response 来自匿名函数。 这是我想要做的:
$ac.autocomplete({
//Call the function here, but what are the parameter request and response???
source: autocomplete(),
minLength: 1
});
这是我要调用的函数
function autoComplete(request, response, url) {
$.ajax({
url: '/Comp/'+url,
dataType: "json",
type: "POST",
success: function (data) {
response($.map(data, function(item) {
return { label: item, value: item, id: item };
}));
}
});
}
非常感谢您的帮助。
【问题讨论】:
标签: jquery-ui jquery-ui-autocomplete