I use the jQuery Autocomplete plugin to display user info in the search box and I can't quite figure out the meaning of the syntax of the following parse function:
$("#UserSearchBox").autocomplete('FindUser.ashx',
{
minChars: 2,
width: 400,
max: 5,
parse: function(data)
{
return $.map(eval(data), function(row)
{
return {
data: row,
value: row.UserID,
result: ""
}
});
},
formatItem: function(item)
{
return FormatUser(item);
});
The plugin works fine: it retrieves JSONified array of user info from an HTTP handler and displays formatted values with the help of the FormatUser function, but I'd really like to know what the following code does (I just copied it from the sample and adjusted for to user object):
return $.map(eval(data), function(row)
{
return {
data: row,
value: row.UserID,
result: ""
}
});
Also, why does the opening brace of the second return must be on the same line as the return statement? If I change code to this:
return $.map(eval(data), function(row)
{
return
{
data: row,
value: row.UserID,
result: ""
}
});
I get an error about an invalid label data. Any ideas? Thanks.