2017-09-06 86 views
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 
      }); 

     }; 
+0

https://jqueryui.com/autocomplete/#custom-data –

+0

谢谢Bhuban Shrestha。正是我需要的。 –

回答