Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby rails-jquery自动完成-为一个列表项组合多个值_Jquery_Ruby_Ajax_Ruby On Rails 3 - Fatal编程技术网

Ruby rails-jquery自动完成-为一个列表项组合多个值

Ruby rails-jquery自动完成-为一个列表项组合多个值,jquery,ruby,ajax,ruby-on-rails-3,Jquery,Ruby,Ajax,Ruby On Rails 3,如何解析rails实例变量的值以创建jQuery的自动完整列表? 因此,我的“/user/search”返回一个实例变量,每个项目有多个值。我想把它们结合起来,作为一个列表项呈现 def search if (params[:term] =~ /[a-zA-Z]/) @result = User.FindLdap("sAMAccountName", params[:term]) else @result = User.FindLdap("idnumber", params

如何解析rails实例变量的值以创建jQuery的自动完整列表? 因此,我的“/user/search”返回一个实例变量,每个项目有多个值。我想把它们结合起来,作为一个列表项呈现

def search
  if (params[:term] =~ /[a-zA-Z]/)
    @result = User.FindLdap("sAMAccountName", params[:term])
  else
    @result = User.FindLdap("idnumber", params[:term])
  end
  respond_to do |format|
    format.html { render :partial => 'text_for_autocomplete'}
    format.js
  end
end
我正在使用jQuery的示例代码,但它有一种方法可以按原样显示每个项目列表。在我的例子中,我检索多个ldap属性,并希望为每个列表项显示这些属性值。 因此,每个列表项应该类似于用逗号分隔的
“#{sAMAccountName}”,“#{idnumber}”
,而不仅仅是在文本字段中键入的idnumber的值

$(function() {
    $("#term").autocomplete({
        source: function (request, response) {
            $.post("/users/search", request, response);
        },
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
                "Selected: " + ui.item.value + " aka " + ui.item.id :
                "Nothing selected, input was " + this.value );
        } #No idea how it can be done here. 
    });
});
我在列表中得到这个,部分呈现的html-


首先,您需要查看。JBuilder是一个强大、定义良好且可靠的json输出解决方案。

为什么不使用json而不是HTML响应,使用JBuilder gem来呈现您想要的响应。您的问题是,您正在从服务器获取HTML及其转义文件。@MilanJaric-谢谢。不知道该怎么做,以前从未做过。我会试试。它和您创建erb html视图一样,这里是headstart@MilanJaric的链接——但是jQuery可以读取到列表中吗?这不是同样的问题吗?它不是html,而是jason.drop-in-question示例JSON数据,我可以用JavaScript编写示例代码