【问题标题】:Bootstrap Typeahead not showing hintBootstrap Typeahead 不显示提示
【发布时间】:2014-08-23 11:21:10
【问题描述】:

我正在使用带有自定义 JSON 响应和带有模板的自定义呈现的 Bootstrap Typeahead。问题是“提示”不再显示,因为结果的自定义呈现。有没有办法指定 JSON 字典结果的“提示”键(在我的例子中是“关键字”)?

通过删除“模板”,提示当然可以工作,但我需要自定义渲染。

var query = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('keyword'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: '/autocomplete?q=%QUERY'
});

$('#idSearch').typeahead({
    hint: true,
    highlight: true,
    minLength: 1
  }, {
    name: 'query',
    source: query,
    templates: {
      suggestion: Handlebars.compile('<p>{{keyword}}</p>')
    }
});

【问题讨论】:

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


【解决方案1】:

在 typeahead.js _updateHint 中:所有的魔法都发生了:我改变了

match = frontMatchRegEx.exec(datum.value);

match = frontMatchRegEx.exec(datum.raw.keyword);

它正在使用自定义模板。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2012-03-03
    相关资源
    最近更新 更多