I never did this before, I am trying to club multiple ldap attributes to be shown for each autocomplete list item.
For example, I search "admin" as sAMAccountName in ldap, and my search function returns two values for each match. sAMAccountName and idnumber, so my list item has to include both sAMAccountName and idnumber. Rather than just sAMAccountName "admin" that was typed in the text field. How can I make jQuery read multiple attributes for each list item?
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.json { render :json=> @result.to_json }
format.js
end
end
$(function() {
$("#term").autocomplete({
source: function (request, response) {
$.post("/users/search", request, response);
},
minLength: 2,
select: function () {}
});
});
See Question&Answers more detail:os