【问题标题】:bootstrap typeahead show no resultsbootstrap typeahead 显示没有结果
【发布时间】:2015-08-28 12:45:29
【问题描述】:

我正在尝试为我的电子邮件字段使用预先输入,因此当管理员搜索电子邮件地址时,会向他们显示选项。很基本。我的源代码是从 php BE 加载的,它从 mysql 收集数据。

所以我有一个输入标签:

<input type="text" name="userEmail" id="email" value="" class="form-control" />

在我的文档准备功能中,我有:

$('#email').typeahead({
    ajax: {
        triggerLength: 3,
        url: '/user/findBootstrap'
    },
    display: 'email'
});

当我输入 :"gbo" 时,我的 php BE 返回一个类似于此的 json:

[{"id":"94","email":"gboitr@server.com"},{"id":"142","email":"gbotyp@stingray-music.com"},{"id":"193","email":"gboychuk@server.com"}]

我通过查看控制台确认我收到了数据。 Typeahead 不会显示任何选项,无论我输入什么。库加载正常(状态 200),我没有 JS 错误

【问题讨论】:

    标签: javascript php bootstrap-typeahead


    【解决方案1】:

    我发现了问题。我今天才下载这个,看发布日期。与documentation page 中指定的相反,更改您要查找的参数名称的参数不是“display”而是“displayField”。

    他们可能与他们的文档不同步......

    希望这篇文章能帮助其他人不要浪费时间...

    所以这里是在我的例子中应该使用的正确语法:

    $('#email').typeahead({
        ajax: {
            triggerLength: 3,
            url: '/user/findBootstrap'
        },
        displayField: 'email' // NOT "display"!!!!!
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      • 2013-01-31
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多