Bootstrap   发布时间:2022-04-18  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了rails,获取bootstrap的typeahead以使用rails和jquery(正常工作)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道是否有人可以帮助我使用Railsjquery自动完成程序“typeahead”

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

<div class="tags">
            <%= f.label :tag_names,"Tags" %>
            <%= f.text_field :tag_names,data: { autocomplete_@R_489_9016@e: tags_path} %>
        </div>

然后转到我的标签控制器的索引操作

def index
       @tags = Tag.order(:Name).where("name like ?","%#{params[:term]}%")
       render json: @tags.map{ |tag| {:label => "#{tag.namE} x #{tag.count}",:value => tag.namE} }
    end

以下是我的jquery ui自动完成代码,然我不认为它在这里非常必要……但这里是它

$(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({
    @R_489_9016@e: function(request,responsE) {
      return $.getJSON($("#lesson_tag_names").data("autocomplete-@R_489_9016@e"),{
        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;
    }
  });
});

自动完成工作,但我似乎无法使用twitters bootstrap.
我试过提供

data: { autocomplete_@R_489_9016@e: tags_path,provide: "typeahead"} %>

$('.typeahead').typeahead()

进入我的application.js文件.但它似乎没有用.我也尝试给我的表单一个id属性

<%= f.text_field :tag_names,id: "autocomplete",data: { autocomplete_@R_489_9016@e: tags_path} %>

@R_644_9447@做点什么

$('#autocomplete').typeahead()

但是通过给我的表单一个:id属性,我的自动完成功能停止工作.所以……我不确定是什么问题.有其他方法吗?

帮助将不胜感激.谢谢

解决方法

我遇到了类似的问题,并最终设计了jQuery UI自动完成功能,如bootstrap typeahead(基本上将bootstrap CSS应用于jQuery UI元素).

我是怎么做到的
http://criticalthinking.tumblr.com/post/17940560421/making-jquery-ui-look-like-bootstrap

大佬总结

以上是大佬教程为你收集整理的rails,获取bootstrap的typeahead以使用rails和jquery(正常工作)全部内容,希望文章能够帮你解决rails,获取bootstrap的typeahead以使用rails和jquery(正常工作)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。