我在我的Rails应用程序中使用Bootstrap-sass和formtastic,我不确定为什么bootstrap-typeahead功能不起作用。Bootstrap Typeahead in Rails
表格部分:
<%= 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也无法正常工作。我无法找到任何代码错误。任何人都可以帮我吗?
UPDATE: 我想它在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
而且还好像预输入无法工作。即)输入“他”不会让我在上述数组中的这三个项目的下拉列表中。有人有想法吗?
'不工作'是什么意思?你有错误吗?什么都没有发生?有什么意外的事情发生? – regulatethis
@regulatethis,由于不工作,我的意思是当我输入几个字母时,typeahead不会被触发。换句话说,如果源是['hello','hey','heyyyy']的数组,那么键入'he'不会显示这三个项目的列表。 –