【发布时间】:2012-12-14 18:47:32
【问题描述】:
我在我的 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
而且似乎预输入仍然无法正常工作。即)输入“他”不会让我得到上述数组中这三个项目的下拉列表。有人有想法吗?
【问题讨论】:
-
not working是什么意思?你有错误吗?什么都没有发生吗?有没有意外发生? -
@regulatethis,不工作,我的意思是当我输入几个字母时,不会触发预输入。换句话说,如果源是 ['hello', 'hey', 'heyyyy'] 的数组,输入 'he' 不会显示这三个项目的列表。
标签: ruby-on-rails twitter-bootstrap autocomplete sass