2015-04-28 111 views
3

我已经设置了typeahead.js版本0.11.1以从geobytes API中提取城市。这里,不只是一个codepen:来自typeahead.js的奇怪行为

http://codepen.io/jeremeevans/pen/OVPram

var cities = new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace(), 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
    remote: { 
     url: "http://gd.geobytes.com/AutoCompleteCity?callback=?&template=<geobytes%20city>,%20<geobytes%20code>&filter=US&q=%QUERY", 
     wildcard: "%QUERY", 
     dataType: "jsonp", 
     transform: function (response) { 
      return response; 
     } 
    }, 
    limit: 10 
}); 

$("#city").typeahead({ 
    minLength: 3, 
    highlight: true, 
    hint: true 
}, { 
    name: "US-Cities", 
    source: cities 
}); 

的怪异行为,我看到的是,当我开始打字西雅图,当我到达“座位”这只是列出两个结果,“ Seaton,IL“和”Seatonville,IL“。我知道API会返回更多的结果,其中包括“华盛顿州西雅图”。此外,如果您开始搜索“Everett”,所有搜索结果将在“Everet”中删除,并且在您到达“Everett”之前保持隐形状态 - 此时会显示“Everett,MA”和“Everett,PA”,但不包含“Everett ,WA“。

与0.11.1版相关的选项和文档的文档在https://github.com/twitter/typeahead.js上相当糟糕 - 我真的很感谢有关如何使用它的一些见解,而不是它的屠夫,它会显示结果。

+0

也许检查出:http://stackoverflow.com/questions/31007825/bootstrap-typeahead-not-showing-hints-as-expected – Reid

回答

1

我遇到了一些物品丢失的情况。 我所做的是将typeahead选项的限制设置为10. 它适用于我。

+0

我有一个类似的问题,并限制到10后,它工作正常,但它是如此奇怪:S – Silence

+0

你可以找到这个错误的原因[这里](https://github.com/twitter/typeahead.js/issues/1415),并有更好的解决方案 – Keyleo