【问题标题】:Can someone tell me and show me the exact files i need for rails jquery autocomplete?有人可以告诉我并告诉我rails jquery自动完成所需的确切文件吗?
【发布时间】:2011-06-21 02:58:50
【问题描述】:

我已经在这里工作了几个小时,即使按照此处的示例和 github 上的示例,我仍然无法让 jquery autocomplete 工作。我应该使用的确切文件是什么,因为我设置了所有内容,路线正确,种子仍然没有 jquery 自动完成,文本框没有做任何事情。

这是我现在正在使用的文件:

autocomplete-rails.js
jquery.js
jquery.min.js
jquery_ujs.js
jquery-ui.js
jquery-ui.min.js

看起来有点不对劲,以前有人做过吗,你有什么文件?

编辑、更新和工作:

确保您拥有正确的文件并将图像放在 public/images 文件夹中。

jquery.js
jquery_ujs.js
jquery-ui.js
rails.js
autocomplete-rails.js
application.js

然后有我的自定义主题:

jquery-ui-1.8.13.custom.css

【问题讨论】:

    标签: jquery ruby-on-rails autocomplete


    【解决方案1】:

    下面需要带有jquery的Rails3项目,你可以在config/application.rb查看

    jquery.js
    rails.js
    

    使用自动完成,您需要:

    jquery-ui.min.js
    

    【讨论】:

      【解决方案2】:

      这是一个适用于我的 jquery 代码片段:

      $.getJSON("/polymerases.json",function(polsFromServer){
          pols = polsFromServer;
          $(#polymerases).autocomplete({
              source: pols
          });
      });
      

      这是我的控制器代码:

      @polymerases = Polymerase.all
      respond_to do |format|
        format.html # index.html.erb
        format.xml  { render :xml => @polymerases }
        format.json do
          response.headers["Cache-Control"] = "public, max-age=60"
          render :json => @polymerases.map(&:formatted_name).to_json
        end
      end
      

      我包括“jquery-1.5.2.min.js”、“jquery-ui-1.8.13.custom.min.js” 以及执行 .autocomplete 调用以将自动完成功能绑定到所选输入框的本地 js 文件(见上文)。

      我认为您不需要 jquery 和 jquery-ui 的非缩小版本。 我不熟悉 _ujs 或 autocomlete-rails 位。

      如果您没有使用 firebug 或 chrome 的开发者模式来单步执行您的 javascript,我强烈建议您这样做。

      此外,查看原始 json 数据可能会有所帮助(例如:http://localhost:3000/polymerases.json

      【讨论】:

        猜你喜欢
        • 2012-09-16
        • 2020-12-31
        • 2013-03-20
        • 2021-11-16
        • 2011-03-10
        • 2014-06-17
        • 1970-01-01
        • 2015-01-03
        • 2015-07-30
        相关资源
        最近更新 更多