jquery's autocomplete plugin was used in the work, but the problem of non-routine use was encountered.
One is the drop-down menu display and fill in the result of the text box requires a different string, that is, display the user name, the department, but filled in the text box is the user name and phone number
The second is after the user select, need to trigger the event, the user's ID to another hidden text box
First of all, I was lazy, so Google on the internet a bit of technical solutions, found to be more complex. After studying AutoComplete's online doc for the purpose of laziness, we found that there was a very simple solution.
The first is to apply the Formatitem and FormatResult functions of AutoComplete
Returns the data set, lazy people have lazy way, the string is separated by commas to represent, one line result:
"Name1,department1,tel1,id1/r/n NAME2, Department2,tel2,id2"
Formatitem: Drop-down menu data display customization, this shows only user name and department
Formatitem:function (data, I, N) {
var array = data.tostring (). Split (', ');
return array[0] + '/' + array[1];
}
FormatResult: Fill in the result of the text box, here fill in the user name and telephone number formatitem:function (data, I, N) {
var array = data.tostring (). Split (', ');
return array[0] + ', ' + array[2];
}
Finally, the callback function, to save the user ID in a hidden text box, this autocomplete provides a sub-function. Result (), which is used to callback other functions after selecting the result
Continue to use the universal Split function to split the result string
$ (' Inputfield '). AutoComplete (URL, {options}). result
(Function (event, data, formatted) {
var array = data.tostring (). Split (', ');
$ ("HiddenField"). Val (Array[3]);
});
The Lazy AutoComplete application is completed.
This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/batman9956/archive/2010/08/17/5816997.aspx