Reputation: 1482
Well I just implement jquery-ui-autocomplete with VB.net in the server side, but it was because I follow an example, does anybody could try to explain (for dummys) how it works this code ?, the part I have no idea about it is in the return (success event):
$("#kSerial").autocomplete({
source: function (request, response) {
dataFromServer = "";
$.ajax({
type: "POST",
url: URL + 'regresaSeriales',
async: false,
contentType: "application/json; charset=utf-8",
data: "{" + "'serial':'" + request.term + "'" + "}",
dataType: "json",
success: function (msg) {
/*This is the part I just don't get it*/
response($.map(msg.d, function (item) {
return {
value: item.serial
};
}));
/*and ends here*/
},
error: function () {
serial = 0;
}
})
},
On my server side I return a list of "serial" objects (List (of T)) and it works fine.
I just follow an example and adapted to my server side code, but I have no idea about how it works the part of the return, I mean I understood that the "source" property accepts a callback, but can't realize how it works the code in the success event of the ajax request.
Indeed I neither get the reason of the 2 parameters in the callback, especially the "request", (request,response).
This is the tutorial I based my code: http://www.dotnetcurry.com/ShowArticle.aspx?ID=515
Upvotes: 0
Views: 376
Reputation: 160261
It takes the response data, grabs the d
object property (an array), iterates over it, and for each item in that array, creates an object with a value
property of the item's serial
property.
The $.map
call puts all those objects in to an array and sends it to the response
function (IIRC part of the autocomplete plugin that spits out the completions).
The request
parameter is just an object containing the search term, or "what's in the text input". This is described in the autocomplete overview docs.
Upvotes: 2