Typeahead.js未显示任何结果

时间:2015-07-30 17:06:11

标签: twitter typeahead.js typeahead bootstrap-typeahead twitter-typeahead

我正试图让Twitter的预先工作,但无法弄清楚如何。据我所知,我已经正确地包含了文件,但它仍然不起作用。

我的代码如下所示:

<!DOCTYPE html>
<html ng-app = "IndexApp">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
    <title></title>

  </head>
  <body>
    <input id="search"/>
    <!--jQuery-->
    <script src = "http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
    <!--typeahead-->
    <script src = "./views/js/typeahead.bundle.js" type="text/javascript"></script>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <!--index.css script-->
    <link rel="stylesheet" href="./views/css/index.css" media="screen" title="no title" charset="utf-8">
    <!--Index.js-->
    <script src = "./views/js/index.js" type="text/javascript"></script>

  </body>
</html>

index.js

var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
  'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
  'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
  'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
  'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
  'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
  'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
  'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
  'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];

$(document).ready(function() {
  $('#search').typeahead({source: states});
})

1 个答案:

答案 0 :(得分:0)

JS fiddle sample (click):

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