自动完成功能在IE中不适用于大数据(> 2500)

时间:2018-11-21 06:11:35

标签: javascript c# asp.net autocomplete

$(function() {
  $("[id$=T_MachineNoName]").autocomplete({
    maxResults: 25,
    maxShowItems: 5,
    delay: 1000,
    minLength: 1,
    source: function(request, response) {
      $.ajax({
        url: '<%=ResolveUrl("~/App/ReqReport/T1700.aspx/GetMachineNo") %>',

        data: "{ 'Factory': '" + document.getElementById('T_FactoryCode').value + "','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],
              val: item.split('***')[1],
              val2: item.split('***')[2],
              val3: item.split('***')[3]
            }
          }))
        },
        error: function(response) {
          alert(response.responseText);
        },
        failure: function(response) {
          alert(response.responseText);
        }
      });
    },
    select: function(e, i) {
      $("[id$=T_MachineNo]").val(i.item.val);
      $("[id$=T_AssetNo]").val(i.item.val);
      $("[id$=T_MachineName]").val(i.item.val2);
      $("[id$=T_MachineNoName]").val(i.item.val);
      $("[id$=T_LineCode]").val(i.item.val3);
    },
    minLength: 1
  });
});

函数GetMachineNo

    [WebMethod]
    public static string[] GetMachineNo(string Factory, string prefix)
    {
        List<string> MachineNo = new List<string>();
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            using (SqlCommand cmd = new SqlCommand())
            {
                if (prefix.Trim() == "")         
                {
                    cmd.CommandText = " Select  SetubiNo,SetubiNo + ': ' + Kimei as Kimei,Kimei as KimeiName,linecode from M_SETUBI where FactoryCode = '001' Order by SetubiNo ";
                }
                else
                {
                    cmd.CommandText = " Select SetubiNo,SetubiNo + ': ' + Kimei as Kimei,Kimei as KimeiName,linecode from M_SETUBI  where FactoryCode = @Factory and SetubiNo like '%' + @SearchText + '%' Order by SetubiNo";
                }  

                cmd.Parameters.AddWithValue("@SearchText", prefix);
                cmd.Parameters.AddWithValue("@Factory", Factory);
                cmd.Connection = conn;
                conn.Open();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        MachineNo.Add(string.Format("{0}***{1}***{2}***{3}", sdr["Kimei"], sdr["SetubiNo"], sdr["KimeiName"],sdr["linecode"]));
                    }
                }
                conn.Close();
            }
        }
        return MachineNo.ToArray();
    } 

此查询cmd.CommandText = " Select SetubiNo,SetubiNo + ': ' + Kimei as Kimei,Kimei as KimeiName,linecode from M_SETUBI where FactoryCode = '001' Order by SetubiNo ";返回2500多个记录。运行IE时,无法在屏幕上显示数据。可能是什么问题?

谢谢

0 个答案:

没有答案