自动完成功能在 minLength 值之前触发

Autocomplete function fires before minLength value

我正在编写自动完成功能,应该在写入第三个元素时触发:

$(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 自动完成功能吗? (https://www.devbridge.com/sourcery/components/jquery-autocomplete/)

如果是这样,则正确的选项称为 "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};
               })
             };
           },
        });
    });

如果没有,你能告诉我这个自动完成功能使用的是什么库吗?