在我的Rails应用程序中,我使用的是引导-sass和表单,我不知道为什么引导-类型提前功能不起作用。
表格部分:
<%= 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尽管如此,打字机似乎仍然无法工作。输入"he“不会让我从上面的数组中下拉掉这三个项目。有谁有主意吗?
发布于 2012-12-30 03:25:05
我认为您需要将html_safe设置为:
{ :'data-source' => '["hello", "hellow", "heaven", "helo", "herr"]'.html_safe }发布于 2012-12-30 09:41:02
在加载页面时,是否调用了Type预报()方法?你需要这样做;
$(function() {
$('input').typeahead();
})您需要为输入指定一个类或id,以便具体地将提前输入绑定到它(Rails可能已经自动为它分配了一个id,我假设您已经特别省略了它)
$(function() {
$('input#my-tag-field-with-a-cool-typeahead').typeahead();
})编辑:
下面这句话对我很管用。它将需要对rails部分进行一些修改,以适应您的情况,但这肯定有效。
<script>
$(function() {
$('input#type_ahead').typeahead()
}
</script>
<%= text_field_tag :test_type, '', data: {provide: 'typeahead', source: "['hello','heythere','heaven']"} %>https://stackoverflow.com/questions/14087538
复制相似问题