0
我在我的asp.net應用程序中使用jQuery自動完成來選擇一個項目名稱。現在我想在該項目下面顯示一個簡短的描述。事情是這樣的: Item Description below Item namejQuery自動完成下拉菜單中的多行選項
我的CS文件C#代碼:
public string[] itemAutocomplete(string prefix)
{
DataSet ds = new DataSet();
ds = autoCompleteItemNameF(prefix);
List<string> autolist = new List<string>();
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
autolist.Add(ds.Tables[0].Rows[i]["good_name"].ToString()+ "-" + ds.Tables[0].Rows[i]["description"].ToString());
}
}
return autolist.ToArray();
我jQuery的功能是:
function item_autocomplete() {
$("[id$=txt_item_name]").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("../Services/AutoComplete.asmx/itemAutocomplete") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("[id$=txt_item_name]").change();
},
minLength: 1
});
};
https://jqueryui.com/autocomplete/#custom-data –
謝謝Bhuban Shrestha。正是我需要的。 –