【问题标题】:autocomplete value does not display不显示自动完成值
【发布时间】:2018-07-17 13:55:44
【问题描述】:

我关注这个网站: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("输入", function () { 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 函数。

你有什么想法吗?

谢谢

【问题讨论】:

  • 好的,我忘记了 typeahead 函数的属性“source”。现在我在 typeahead.js 上有这个错误: Uncaught TypeError: Cannot read property 'hasOwnProperty' of undefined

标签: jquery twitter-bootstrap-3 typeahead.js


【解决方案1】:

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

试试这个:

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

【讨论】:

    猜你喜欢
    • 2017-10-19
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多