Javascript 在minLength值之前激发Autocomplete函数
我正在编写自动完成函数,该函数应在写入第三个元素时启动:Javascript 在minLength值之前激发Autocomplete函数,javascript,jquery,jquery-ui-autocomplete,Javascript,Jquery,Jquery Ui Autocomplete,我正在编写自动完成函数,该函数应在写入第三个元素时启动: $(document).ready(function() { $('#button').autocomplete({ minLength: 3, serviceUrl: '{{contextPath}}/someUrl', paramName: "suggestion", onSelect: function (suggestion) { al
$(document).ready(function() {
$('#button').autocomplete({
minLength: 3,
serviceUrl: '{{contextPath}}/someUrl',
paramName: "suggestion",
onSelect: function (suggestion) {
alert("test");
},
transformResult: function(response) {
return {
suggestions: $.map($.parseJSON(response), function(item) {
return { value: item.x, data: item.y };
})
};
},
});
});
但是,此函数与第一个函数一起启动。
有人知道为什么吗?您正在使用Ajax自动完成功能吗?() 如果是这样,则正确的选项称为“minChars”,而不是“minLength” 因此,请尝试使用:
$(document).ready(function() {
$('#button').autocomplete({
minChars: 3,
serviceUrl: '{{contextPath}}/someUrl',
paramName: "suggestion",
onSelect: function (suggestion) {
alert("test");
},
transformResult: function(response) {
return {
suggestions: $.map($.parseJSON(response), function(item) {
return { value: item.x, data: item.y};
})
};
},
});
});
如果没有,你能告诉我你在使用什么库来实现这个自动完成功能吗?好吧,根据我假设的标记,但是因为它甚至没有像
serviceUrl
这样的设置,你的猜测可能是正确的。与minChars一起使用!谢谢您。但是我使用的是jquery.autocomplete.js库