【问题标题】:show suggestions in Handlebar template using bootstrap typeahead使用 bootstrap typeahead 在 Handlebar 模板中显示建议
【发布时间】:2013-06-28 07:03:52
【问题描述】:

我可以使用 bootstrap typeahead 和以下代码显示建议:

    var xyz =JSON.stringify(this.collection.toJSON());      

    var jasonxyzObj = $.parseJSON(xyz);
    var xyzArray = [];

    for (var i = 0; i < jasonxyzObj.length; i++) {
       xyzArray.push(jasonxyzObj[i].id'');
    }

    $(".abc-class").typeahead({
        source: xyzArray,

    });

但我想将建议显示为建议中的 id 名称计数,而不仅仅是使用 hbs 文件的 id。我的 hbs 文件如下所示:abc.hbs (ABC)

    <table class="table">
    <tr>
     <td>{{name}}</td>
     <td>{{id}}</td>
     <td>{{count}}</td>
    </tr>
    </table>

我尝试了下面的代码,但在建议中得到了单个字母:

var xyz =JSON.stringify(this.collection.toJSON());      

    var jasonxyzObj = $.parseJSON(xyz);
    var xyzArray = [];

    for (var i = 0; i < jasonxyzObj.length; i++) {
       xyzArray.push(jasonxyzObj[i].id'');
    }

    $(".abc-class").typeahead({
        source: xyz,
          template: ABC,
        engine:Handlebars

    });

当我在源代码中只给出 xyz 时,我会收到单个字母的建议。但是当我在源代码中给出 jasonxyzObj 时,我收到错误:第 6 行的 bootstrap.min.js 中的“TypeError:e.toLowerCase 不是函数”。我的引导版本是“2.3.1”。

使用 bootstrap typeahead 在车把文件 (HBS) 中显示建议的正确方法是什么。

【问题讨论】:

    标签: backbone.js requirejs handlebars.js bootstrap-typeahead


    【解决方案1】:

    目前与 Twitter Bootstrap 一起打包的 typeahead 插件不允许您使用除字符串数组之外的任何东西。您显示的代码看起来像是您正在尝试使用 Twitter typeahead 插件,该插件实际上是一个独立于 Bootstrap 的插件。

    博文: https://blog.twitter.com/2013/twitter-typeaheadjs-you-autocomplete-me

    Github 回购: https://github.com/twitter/typeahead.js

    我认为,如果您将其包含在您的项目中,它可能会开始为您工作。

    【讨论】:

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