• 自动补全Typeahead


    采用 Typeahead (Bootstrap-3-Typeahead-master)

     

    <script type="text/javascript"
        src="/js/plugins/bootstrap3-typeahead.min.js"></script>
    <script type="text/javascript">//自动补全
            $("#loginInfoDisplay").typeahead({
                minLength:3,//最小开始查询的字符个数
                items:5,//下拉列表中最多显示的条数
                source:function(query,process){//加载数据源
                    $.ajax({
                        dataType:"json",
                        type:"POST",
                        url:"vedioAuth_autocomplate.do",
                        data:{str:query},
                        success:function(data){//这个data就是一个json对象的数组{id:xx,username:xxxx}
                            if(data && data.length){
                                process(data);//process就是交给我们获得数据之后用来调用的方法,这个方法执行了,下拉列表就出来了
                            }
                        }
                    });
                },
                //用来告诉typeahead怎么显示json对象中的内容
                displayText:function(item){
                    return item.username
                }
            }).change(function(){
                var current = $(this).typeahead("getActive");
                if(current){
                    $("#loginInfoValue").val(current.id);
                }
            });
    </script>
                     <div class="col-sm-6">
                                    <div class="dropdown" id="autocomplate">
                                        <input type="text" class="form-control" id="loginInfoDisplay"
                                            autocomplete="off" /> <input type="text" name="loginInfoValue" id="loginInfoValue"/>
                                    </div>
                                </div>

    =========================================================================

    /**
         * 用于用户的automcomplate
         */
        @RequestMapping("vedioAuth_autocomplate")
        @ResponseBody
        public List<Map<String, Object>> autoComplate(String str){
            return userinfoService.autoComplate(str);
        }

    =============================================================

    @Override
        public List<Map<String, Object>> autoComplate(String keyword) {
            
            return this.userinfoMapper.autoComplate(keyword);
        }

    =============================================================

    <select id="autoComplate" resultType="hashmap">
          SELECT id,username 
          FROM logininfo WHERE username LIKE concat(#{keyword},'%')
      </select>
  • 相关阅读:
    [BUGCASE]CI框架的post方法对url做了防xss攻击的处理引发的文件编码错误
    [BUGCASE]Webpack打包报JavaScript堆内存泄漏的错误
    [BUGCASE]前端码案概述
    实现复杂状态机的一种思路
    日期选择组件(DatePicker)的实现
    前端开发的积木理论——像搭积木一样做前端开发
    GitHub 使用
    数组循环常用几种方法
    react 如何引入图片, 背景图片, 盒子上下左右居中
    react select案例
  • 原文地址:https://www.cnblogs.com/jokerq/p/8623827.html
Copyright © 2020-2023  润新知