tagsinput typeahead不工作

时间:2015-04-27 22:10:06

标签: json twitter-bootstrap

不知道为什么我无法使用此模块,tagsinput工作正常。但是唱片公司出于某种原因并不是这样。我正在使用twitter typeahead: https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js

<html>
<head>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- Optional theme -->
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">

    <!-- Tagsinput -->
    <link rel="stylesheet" href="tagsinput/bootstrap-tagsinput.css">

</head>

<body>
    <input value="Amsterdam,Washington" type="text" data-role="tagsinput">

    <script>
        var bestPictures = new Bloodhound({
          datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
          queryTokenizer: Bloodhound.tokenizers.whitespace,
          prefetch: 'tagsinput/cities.json',
        });

        $('input').typeahead(null, {
          name: 'best-pictures',
          display: 'value',
          source: bestPictures
        });
    </script>

    <!-- Latest compiled and minified JavaScript -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="tagsinput/bootstrap-tagsinput.js"></script>
    <script src="tagsinput/typeahead.bundle.js"></script>
</body>
</html>

Json文件:

[ "Amsterdam",
  "London",
  "Paris",
  "Washington",
  "New York",
  "Los Angeles",
  "Sydney",
  "Melbourne",
  "Canberra",
  "Beijing",
  "New Delhi",
  "Kathmandu",
  "Cairo",
  "Cape Town",
  "Kinshasa"
]

1 个答案:

答案 0 :(得分:0)

这可能是与您的代码输入配置相关的问题。

无论如何,您可以尝试通过tags-input插件设置twitter typeahead:

    var bestPictures = new Bloodhound({
      datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
      queryTokenizer: Bloodhound.tokenizers.whitespace,
      prefetch: 'tagsinput/cities.json',
    });

    $('input').tagsinput({
      typeaheadjs: [null, {
        name: 'best-pictures',
        display: 'value',
        source: bestPictures
      }]
    });