How to manipulate the data return in Json Callback
i have a very simple autocomplete textbox to show the entries.. i want to manipulate the data return in callback function.. i am not sure how to do that .. please help..
UPDATED jquery code
$(document).ready(function () { $('#txtAC').autocomplete({
source: '@Url.Action("ShowTitle","Home")',
dataType: 'json',
parse: function (data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
rows[i] = { data: data[i], value: data[i].Title, result: data[i].Title };
}
return rows;
},
formatItem: function (item) {
return item.Title + '(' + item.Body + ')';
},
});
});
here is my controller action which return the title & description
public JsonResult ShowTitle(string term)
{
var result = (from t in db.DBEntries
where t.Title.Contains(term)
select new { Title = t.Title, Body = t.Body }开发者_Go百科).ToList();
return Json(result.ToArray(),JsonRequestBehavior.AllowGet);
}
its showing me the Title in autoComplete but i want to show like this Title - Description
seeking help...
Something like this?
return {value: item.Title + ' - ' + item.Description}
精彩评论