jQuery自动完成选择标签和值并仅显示标签

时间:2015-05-08 06:27:57

标签: jquery asp.net

我尝试使用jQuery自动完成功能搜索客户数据。我有以下情况。

客户名称和手机号码应显示为列表选择,在选择时,我必须只显示客户名称到自动填充文本框。

我尝试过以下代码,但它无法正常工作。

$("#txtServiceCustSearch").autocomplete(
           {           
              source: function (request, response) {
                  $.ajax({
                      url: '<%=ResolveUrl("~/AutoComplete.asmx/GetServiceCustomer") %>',
                      data: "{ 'prefix': '" + request.term + "'}",
                      dataType: "json",
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      success: function (data) {
                          $("[id*='grvHistory']").empty();
                          response($.map(data.d, function (item) {                             
                              return {
                                  label: item.split('$')[0],
                                  val: item.split('$')[1],
                                  val1: item.split('$')[2],
                                  val2: item.split('$')[3],
                                  val3: item.split('$')[4],
                                  val4: item.split('$')[5],
                                  val5: item.split('$')[6],
                                  val6: item.split('$')[7],
                                  val7: item.split('$')[8]
                              }
                          }))
                      },
                      error: function (response) {
                          alert(response.responseText);
                      },
                      failure: function (response) {
                          alert(response.responseText);
                      }
                  });
              },
              select: function (e, i) {
                  $("#txtServiceAddress").val(i.item.val);
                  $("#txtPinCode").val(i.item.val1);
                  $("#txtServiceContactNo").val(i.item.val2);
                  $("#txtLandmark").val(i.item.val3);
                  $("#txtEmailID").val(i.item.val4);
                  $("#txtServiceDOB").val(i.item.val5);
                  $("#txtServiceMobileNo").val(i.item.val6);
               $("#txtServiceCustSearch").val(i.item.val7); },
              close: function (e, i) {
              },
              minLength: 3
          });

0 个答案:

没有答案
相关问题