Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        5年前关闭。
                                                                                            
                
        
我正在尝试使用“带标题的多个节”的第一页,但是很难弄清楚这一点。

JS BIN在这里:http://jsbin.com/degu/5/edit?html,css,js,output

JSON文件存储在本地服务器上,其中包含来自twitter-typehead网站的默认数据。

更新的JS BIN文件:http://jsbin.com/babe/1/edit?html,js,output

最佳答案

使用JS Bin,我重新创建了在typeahead.js示例中找到的“ Dead simple”示例:

http://jsbin.com/levo/1

请注意,此站点上还有很多其他Typeahead.js的示例,这些示例使用了jsfiddle.net,我个人更喜欢JS Bin。

您知道的来源是:

// instantiate the bloodhound suggestion engine
var numbers = new Bloodhound({
  datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.num); },
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  local: [
    { num: 'one' },
    { num: 'two' },
    { num: 'three' },
    { num: 'four' },
    { num: 'five' },
    { num: 'six' },
    { num: 'seven' },
    { num: 'eight' },
    { num: 'nine' },
    { num: 'ten' }
  ]
});

// initialize the bloodhound suggestion engine
numbers.initialize();

// instantiate the typeahead UI
$('.typeahead').typeahead(null, {
  displayKey: 'num',
  source: numbers.ttAdapter()
});


要使“带标题的多个节”示例工作,您需要在本地进行开发,否则,您需要使用远程源来使JS Bin访问本地托管的json文件。

请注意,您的示例(即http://jsbin.com/babe/1/edit)无法正常工作的原因是:


您缺少对jQuery 1.9+的引用
您忘记添加开头正文和div标签


另外,我建议您使用“ script”元素包含对库的依赖关系,而不是将整个库放入JS Bin“ Javascript”部分。为使用引用的库的代码保留“ JavaScript”部分。

关于javascript - super 基本的twitter-typehead页面无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21635644/

10-12 16:44
查看更多