jQuery的自动完成极限结果 [英] jquery autocomplete limit results

查看:129
本文介绍了jQuery的自动完成极限结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用10自动完成的同时限制了行号。数据是从数据库。有没有像MAXROWS'什么的任何属性?我不希望添加滚动。

请提前说明方法的感谢。

我的code是:

  $(#iIdlbl)。自动完成({
                    来源:函数(请求,响应){                    。VAR值=的jQuery(#iIdlbl)VAL();
                    $阿贾克斯({
                        网址:'getiId.html',
                        数据类型:JSON,
                        数据:{
                            过滤器:值
                        },
                        成功:功能(数据){                            响应(jQuery.map(data.iList,函数(项目){
                                                返回{
                                                    值:item.iId,
                                                    关键:item.iId                                                };
                                            }));
                },
                错误:功能(XMLHtt prequest,textStatus,errorThrown){
                    $ .loader('接近');
                }
                    });                },                的minLength:0,
                打开:功能(){
                    $(本).removeClass(
                            UI角一切)。addClass(
                            UI-角顶);
                },                关闭:函数(){
                    $(本).removeClass(
                            UI角顶)。addClass(
                            UI-角落都);
                },
                选择:函数(事件,UI){
                    sea​​rchById(ui.item.value);
                }                });


解决方案

最简单的方法是限制你的源返回结果的数量。

所以,在 getiId.html ,限制的项目数为10

I need to limit the row numbers with 10 while autocomplete. Data is from db. Is there any attribute like 'maxrows' or something?. I don't want to add the scroll.

please suggest method thanks in advance.

my code is:

$("#iIdlbl").autocomplete({
                    source : function(request, response) {      

                    var value = jQuery("#iIdlbl").val();


                    $.ajax( {
                        url : 'getiId.html',
                        dataType : 'json',
                        data : {
                            filter : value
                        },
                        success : function(data) {

                            response(jQuery.map(data.iList,function(item) {
                                                return {
                                                    value : item.iId,
                                                    key : item.iId

                                                };
                                            }));


                },
                error : function(XMLHttpRequest,textStatus,errorThrown) {
                    $.loader('close');
                }
                    });

                },

                minLength : 0,
                open : function() {
                    $(this).removeClass(
                            "ui-corner-all").addClass(
                            "ui-corner-top");
                },

                close : function() {
                    $(this).removeClass(
                            "ui-corner-top").addClass(
                            "ui-corner-all");
                },
                select : function(event, ui) {
                    searchById(ui.item.value);
                }

                });  

解决方案

The easiest way is to limit the number of returned results in your source.

so, in getiId.html, limit the number of items to 10

这篇关于jQuery的自动完成极限结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆