【问题标题】:twitter typeahead.js + bootstrap tagsinput = Object [object Object] has no method 'setQuery'twitter typeahead.js + bootstrap tagsinput = Object [object Object] 没有方法'setQuery'
【发布时间】:2013-12-30 16:45:04
【问题描述】:

我正在使用带有 Bootstrap 标签输入的 Twitter typeahead。代码如下所示:

$(selector).tagsinput('input').typeahead({
    name:'tags',
    remote: "/admin/tags/search/%QUERY?format=json"
}).bind('typeahead:selected', function (object, datum) {
    $(selector).tagsinput('add', datum);
    $(selector).tagsinput('input').typeahead('setQuery', 'test');
});

这几乎是从这里的示例复制而来的:http://timschlechter.github.io/bootstrap-tagsinput/examples/bootstrap3/ (要查看原始示例,您需要单击 Typeahead 部分中的“显示代码”。

它与$(selector).tagsinput('input').typeahead('setQuery', ''); 行不同,这给了我这个错误:

Uncaught TypeError: Object [object Object] has no method 'setQuery' 

在建议被添加到标签列表后,该行应该重置已经输入到预输入控件的文本。如果我像这样在偶数回调之外添加同一行:

$(selector).tagsinput('input').typeahead('setQuery', 'test');

它有效。

我注意到购买调试的唯一一件事是$(selector).tagsinput('input').typeahead 指向事件处理函数内外的不同函数。

有什么想法吗?

【问题讨论】:

  • 你好,我也有同样的问题,你解决了吗?

标签: javascript jquery twitter-bootstrap typeahead.js


【解决方案1】:

我写这个

$("#TagsInput").tagsinput("input").typeahead("val", "");

【讨论】:

    【解决方案2】:

    我有同样的问题。 There你可以看到正确的使用方法。

    你必须在第二行设置 typeahead:

    $(selector).tagsinput();
    $(selector).tagsinput('input').typeahead('setQuery', '');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 2015-06-09
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多