2017-09-06 7 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

ありがとうブバン・シュレスタ。ちょうど私が必要なもの。 –

答えて

関連する問題