jQuery UI 从鼠标选择后未选择自动完成值

jQuery UI autocomplete values not getting selected after selection from mouse

我使用 jquery 创建了 autocomplete 的功能。它工作得很好,但例如:

每当我使用鼠标键入文本和 select 列表中的值时,它会第一次 selected 但如果我再次键入并 select 列表.这些值没有得到 selected。

下面是我的代码。我不明白为什么它不工作。

$(document).ready(function () {
$('#txtAssignVendor').autocomplete({
    source: AppConfig.PrefixURL + 'VendorData.ashx',
    position: {
        my: "left bottom",
        at: "left top",
    }
});});

更新

下面的Vendor.ashx文件是我使用的代码

public void ProcessRequest(HttpContext context)
    {
        try
        {
            //DataTable dt = new DataTable();
            string term = context.Request["term"] ?? "";
            List<string> VendorNames = new List<string>();
            string connString = ConfigurationManager.ConnectionStrings["ConnAPP_NEIQC_PLNG"].ConnectionString;

            using (OracleConnection conn = new OracleConnection(connString))
            {
                OracleCommand cmd = new OracleCommand("", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = ConfigurationManager.AppSettings["PackageName"].ToString() + ".GET_VENDOR_NAME";
                cmd.Connection = conn;

                cmd.Parameters.Add(new OracleParameter { ParameterName = "P_VENDORNAME", Value = term, OracleDbType = OracleDbType.NVarchar2, Direction = ParameterDirection.Input });

                cmd.Parameters.Add(new OracleParameter
                {
                    ParameterName = "TBL_DATA",
                    OracleDbType = OracleDbType.RefCursor,
                    Direction = ParameterDirection.Output
                });

                if (conn.State != ConnectionState.Open) conn.Open();
                OracleDataAdapter da = new OracleDataAdapter(cmd);

               // da.Fill(dt);

                OracleDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    VendorNames.Add(dr["VENDORNAME"].ToString());
                    //VendorNames.Add(string.Format("{0}-{1}", dr["VENDOR_CODE"], dr["VENDOR_NAME"]));
                }
            }

            JavaScriptSerializer js = new JavaScriptSerializer();
            context.Response.Write(js.Serialize(VendorNames));
        }
        catch (Exception ex)
        {                
            throw;
        }    
    }

您能否提供请求的预期 JSON 结果?

因为我没有 JSON 输出,所以我使用基于 AJAX 的自动完成功能制作了一个工作示例。您应该输入 3 个字符才能开始搜索。

$( "#country" ).autocomplete({
 source: function( request, response ) {
  $.ajax({
   type: 'GET',
   url: "https://restcountries.eu/rest/v2/name/" + request.term,
   dataType: "json",
   success: function( resp ) {
          var data = []
          resp.forEach(d => {data.push(d.name)})
             response(data)
   }
  });
 },
 minLength: 3,
 select: function( event, ui ) {
  console.log( ui.item ?
   "Selected: " + ui.item.label :
   "Nothing selected, input was " + this.value);
 },
});
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<input type="text" id="country" />