【问题标题】:JQuery Autocomplete textbox asp.net Limit resultJQuery 自动完成文本框 asp.net 限制结果
【发布时间】:2017-10-19 02:20:03
【问题描述】:

我正在开发一个文本框的自动完成功能,并且需要一次获取十个结果,并带有一个选项,即获取更多超链接。目前它获取所有结果。

到目前为止,我的代码附在下面。你能提供指导吗?

$(document).ready(function(){
            $('#<%=txtEmployeeName.ClientID%>').autocomplete({
                source: function (request, response) {
                    $("#loading").show();
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "AccountDisclosureSearch.aspx/SearchEmpByText",
                        data: "{ 'empName':'" + request.term + "'}",
                        dataType: "json",
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.split(";")[0],
                                    val: item.split(";")[1]
                                //    name: item.split("|")[0]
                                }
                            }))
                            $("#loading").hide();
                        },

                        error: function (response) {
                            alert(response.responseText);
                            $("#loading").hide();
                        }
                    });
                },
                select: function (e, i) {

                 //   $("#<%=hempid.ClientID %>").val(i.item.val);
                    storeEmployee(i.item.label, 0, i.item.val);

                },

                 open: function(){
                $('.ui-autocomplete').css('width', '220px');
                },
                minLength: 3

            });
        });

【问题讨论】:

  • 在您的后端查询中,您可以设置限制,例如 LIMIT 0,10
  • @stackoverflkowfan 您是否有权访问 AccountDisclosureSearch.aspx 可能是的,您可以在 JSON 响应中添加一个额外的项目,以便自动添加所需的元素..

标签: jquery asp.net autocomplete


【解决方案1】:

您可以使用maxResults 或maxShowItems,如下所示:

$(document).ready(function(){
            $('#<%=txtEmployeeName.ClientID%>').autocomplete({
             maxResults:10,
             or
             maxShowItems:10,
             or 
             maxHeight: 150,
             source: function (request, response) {
             //whatever you have
             }
            });
});

更多信息请查看Here

【讨论】:

  • 感谢 Lalit,但我还需要在底部添加一个超链接来显示剩余的或接下来的 10 个 ...我正在努力解决这个问题
  • 你有必要使用超链接吗?否则你可以使用maxHeight和滚动条
  • 我可以试试 maxheight 但是超链接是原始要求:)
  • 这是记得点击你忘记的勾号来接受答案。 @stackoverflkowfan
猜你喜欢
  • 1970-01-01
  • 2011-05-03
  • 2017-08-26
  • 2011-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-24
相关资源
最近更新 更多