1

我正在尝试将Bootstrap Tags Input v.0.5.0 与typeahead.js v.0.11.1 和 Bootstrap v3.3.5 一起使用。它对我有用,但我无法输入我的 typeahead 源数组中不存在的标签。为了允许输入源数组中不存在的项目,我需要更改什么?

这是我的示例 html:

<input type="text" id="dailyTagsInput" name="dailyTagsInput" class="form-control">

这是我的示例js:

    $scope.states = ['Alabama', 'Alaska', 'Arizona'];

$scope.statesSource = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.whitespace,
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  local: $scope.states
});

$('#dailyTagsInput').tagsinput({
  maxChars: 50,
  maxTags: 10,
  trimValue: true,
  freeInput: true,
  typeaheadjs: {
    name: 'states',
    source: $scope.statesSource.ttAdapter()
  }
});
4

1 回答 1

1

当前的tagsinput 文档表明自由输入“只有在使用字符串作为标签时才有可能”。这让我觉得使用 Typeahead + Bloodhound 作为来源可能会与freeInput选项发生冲突。

我会尝试将 typeahead 源添加为字符串数组,而不是使用 Bloodhound。

$('#dailyTagsInput').tagsinput({
  ...
  typeaheadjs: {
    name: 'states',
    source: $scope.statesSource
  }
});
于 2015-09-14T14:22:34.510 回答