JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – 确定rails3 jquery autocomplete插件的结果大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_772_1@我正在使用 https://github.com/crowdint/rails3-jquery-autocomplete,它似乎正在工作.唯一的问题是让我说我​​有一个字段在所有帖子标题上执行自动完成,但我希望它只显示用户创建的帖子的标题.

有没有办法做这样的事情?即一个find_by还是什么?

谢谢!

-Elliot

编辑

它在文档中说:

If you want to display a different version of what you're looking for,you can use the :display_value option.

This options receives a method name as the parameter,and that method will be called on the instance when displaying the results.

class Brand < ActiveRecord::Base
  def funky_method
    "#{self.namE}.camelize"
  end
end


class ProductsController < Admin::BaseController
  autocomplete :brand,:name,:display_value => :funky_method
end
In the example above,you will search by name,but the autocomplete list will display the result of funky_method

我觉得这可以用来做我想要完成的事情,但我不知道从哪里开始?

解决方法

你应该覆盖方法get_item,例如在这些情况下我将过滤用户列表虑到最后一个:
class UsersController < ApplicationController
    autocomplete :user,:email,:full => true

    def index
        @users = User.all
    end

    def get_items(parameters)
        [User.last]
    end

我认为最后一次提交之一,改变了方法(#get_items)的名称.检查autocomplete.rb文件的版本.

在这里查看:https://github.com/crowdint/rails3-jquery-autocomplete/commit/b3c18ac92ced2932ac6e9d17237343b512d2144d#L1R84.

大佬总结

以上是大佬教程为你收集整理的javascript – 确定rails3 jquery autocomplete插件的结果全部内容,希望文章能够帮你解决javascript – 确定rails3 jquery autocomplete插件的结果所遇到的程序开发问题。

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

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