自动完成值不显示

autocomplete value does not display

我关注这个网站:https://github.com/biggora/bootstrap-ajax-typeahead

我将输入文本创建为:

<div class="col-xs-2">
    <input type="text" class="form-control typeahead" name="user" id="user" placeholder="autocomplete" />
</div>

在我的 JS 脚本中:

$('#user').on("input", 函数 () { var login = $("#user").val();

    $.ajax({
        type: "POST",
        async: false,
        cache: false,
        url: "/user/ajaxSearch",
        data: 'login=' + login,
        dataType: 'json',
        success: function(data) {
            var typeaheadSource = ['John', 'Alex', 'Terry'];
            $('.typeahead').typeahead(typeaheadSource);
        }
    });
});

我没有错误,但是没有列表显示。我调试了我的代码,调用了 typeahead 函数。

你有想法吗?

谢谢

您没有正确调用插件。它需要一个对象作为选项,源是其中一项。

试试这个:

 var typeaheadSource = ['John', 'Alex', 'Terry'];
 $('.typeahead').typeahead({source: typeaheadSource});