我在我的 Rails 应用程序中使用 Bootstrap-sass 和 formtastic,但我不确定为什么 bootstrap-typeahead 功能不起作用。
表格部分:
<%= f.input :tag, :input_html => { :'data-provide' => "typeahead", :'data-source' => '["hello", "hellow", "heaven", "helo", "herr"]' } %>
application.js 清单:
//= require bootstrap-typeahead //typeahead is correctly loaded, checked with firebug
结果 HTML 源代码:
<input :data-minLength="2" data-provide="typeahead" data-source="["hello", "hellow", "heaven", "helo", "herr"]"
最后,我需要自定义 typeahead 以获得我想要的性能,但即使是这个简单的 javascript 由于某种原因也无法正常工作。我找不到代码有什么问题。有人可以帮我吗?
更新: 我以javascript方式尝试如下:
<script> //call typeahead
$(function() {
$('input#type_ahead').typeahead({
'source' : ["hello", "heaven", "heythere"]
});
})
</script>
<%= f.input :tag_list, :input_html => { :id => "type_ahead" }, %> //input tag
而且似乎预输入仍然无法正常工作。即)输入“他”不会让我得到上述数组中这三个项目的下拉列表。有人有想法吗?