rails,获得引导';使用rails和jquery(正常工作)时,请提前键入

rails,获得引导';使用rails和jquery(正常工作)时,请提前键入,jquery,ruby-on-rails,twitter-bootstrap,typeahead,Jquery,Ruby On Rails,Twitter Bootstrap,Typeahead,我想知道是否有人能帮我用rails和jQueryAutoComplete引导“typeahead” 在我的“新”动作模板中,我有 <div class="tags"> <%= f.label :tag_names, "Tags" %> <%= f.text_field :tag_names, data: { autocomplete_source: tags_path}

我想知道是否有人能帮我用rails和jQueryAutoComplete引导“typeahead”

在我的“新”动作模板中,我有

        <div class="tags">
            <%= f.label :tag_names, "Tags" %>
            <%= f.text_field :tag_names,
                data: { autocomplete_source: tags_path} %>
        </div>
下面是我的jQueryUIAutoComplete代码,虽然我不认为这在这里是非常必要的…但在这里它是以防万一的

  $(function() {
  var extractLast, split;
  split = function(val) {
    return val.split(/,\s*/);
  };
  extractLast = function(term) {
    return split(term).pop();
  };
  return $("#lesson_tag_names").bind("keydown", function(event) {
    if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
      return event.preventDefault();
    }
  }).autocomplete({
    source: function(request, response) {
      return $.getJSON($("#lesson_tag_names").data("autocomplete-source"), {
        term: extractLast(request.term)
      }, response);
    },
    search: function() {
      var term;
      term = extractLast(this.value);
      if (term.length < 1) {
        return false;
      }
    },
    focus: function() {
      return false;
    },
    select: function(event, ui) {
      var terms;
      terms = split(this.value);
      terms.pop();
      terms.push(ui.item.value);
      terms.push("");
      this.value = terms.join(", ");
      return false;
    }
  });
});

进入我的application.js文件。但它似乎不起作用。我也试着给我的表单一个id属性

                <%= f.text_field :tag_names, id: "autocomplete",
                data: { autocomplete_source: tags_path} %>
然而,通过给我的表单一个:id属性,我的自动完成停止工作。所以…我真的不确定出了什么问题。还有其他的方法吗


非常感谢您的帮助。谢谢

我遇到了一个类似的问题,并最终将jQuery UI自动完成的样式设置为bootstrap typeahead(基本上是将bootstrap CSS应用于jQuery UI元素)

我是如何做到的:

哦,太好了,你有没有找到一种方法让别人打字时把字母加粗?@Crystal。。我没有试过,但我想它可能需要一些定制的JS..嗯,我想我不需要加粗了。这对我没用,哈哈。感谢您回复并发送该有用链接=)
data: { autocomplete_source: tags_path, provide: "typeahead"} %>
$('.typeahead').typeahead()
                <%= f.text_field :tag_names, id: "autocomplete",
                data: { autocomplete_source: tags_path} %>
    $('#autocomplete').typeahead()