3

尝试使用 tagsinput & typeahead 时,我不断收到此错误。

html:

<section id="examples">
  <div class="example example_typeahead">
    <h3>Typeahead</h3>
    <div class="bs-example">
      <input class="testing" type="text" value="nope" />
    </div>
  </div>
</section>

javascript:

var data = ['yes', 'yesyes', 'no', 'nope', 'yes again'],
  elt = $('.testing');

elt.tagsinput({
  typeahead: {
    source: data
  },
});

单击列表中的项目后,我收到应用错误。我还注意到我输入的文本没有被删除。我已经搜索了其他类似的问题,但没有找到有效的答案。

注意:我将这个插件用于预先输入https://github.com/bassjobsen/Bootstrap-3-Typeahead 和这个插件用于标签输入http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/

4

1 回答 1

3

猜想,但我不确定,已经进行了 bootstrap-tagsinput 更新,它以某种方式破坏了它处理“旧”引导输入的方式。我发现了两个错误,但没有完全找到原因。

第一个问题
错误“无法读取未定义的属性‘应用’ ”在预输入中引发,是由预输入尝试以未定义值为目标引起的。问题也在这里。我已经为此提出了拉取请求(单击以获取详细信息)。希望我的建议会被合并,如果没有,你可以下载这个分叉的 repo。拉取请求现在已合并到 master 中。

第二个问题
当讨厌的异常是历史时,我注意到在预先输入中进行选择后,bootstrap-tagsinput not 正在清理。进行了选择,但整个字符串或部分字符串仍保留在输入框中。这可以通过使用afterSelect处理程序来解决:

$('#someElement').tagsinput({
  typeahead: {
    source: data,
    afterSelect: function() {
       this.$element[0].value = '';
    }
  }
}) 

通过这两个更改,bootstrap-tagsinput 和 boostrap3-typeahead 可以按预期工作。见演示-> http://jsfiddle.net/bao3vk2m/

于 2016-02-18T18:50:35.087 回答