It's hard to tell what are attributes in User model but I presume they are sAMAccountName and idnumber, so here is replacement for your source method in jQuery autocomplete
source: function( request, response ) {
$.ajax({
url: "/users/search",
dataType: "json",
data: {
term: request.term
},
success: function( data ) {
// remove users in line below if JSON is not prepanded with users attribute
response( $.map( data.users, function( user ) {
return {
// this is formated string which will be visible in autocomplete list
// example "123213, admin"
label: user.idnumber + ", " + user.sAMAccountName,
value: user.idnumber
}
}));
}
});
},
The code above will convert (map) response from server to format
[ { label: "<idnumber>, <sAMAccountName>" , value: "<idnumber>" }, .....]
Don't worry jQuery autocomplete knows how to handle this array ;)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…