美文网首页
select2 搜索分页例子

select2 搜索分页例子

作者: LeftJoin | 来源:发表于2018-02-01 15:01 被阅读0次
      $("#serachCar").select2({
            theme: "bootstrap",
            placeholder: "Search for a repository",
            minimumInputLength: 2,//最少输入多少个字符后开始查询
            language: "zh-CN",
          allowClear:true,
            ajax: {
                type:'GET',
                url: "{:U('getVehiclePage')}",
                dataType: 'json',
                delay: 250,
                data: function (params) {
                    return {
                        code: params.term, // search term 请求参数 , 请求框中输入的参数
                        page: params.page || 0,
                        size: 10,
                    };
                },
                processResults: function (data, params) {
                    params.page = params.page || 0;
                    return {
                        results: data.rows,//itemList
                        pagination: {
                            more: (params.page * 10) < data.total
                        }
                    };
                },
                cache: true
            },
            escapeMarkup: function (markup) { return markup; }, // 自定义格式化防止xss注入
            templateResult: repoFormatResult, // omitted for brevity, see the source of this page
            templateSelection: repoFormatSelection,
        });
        function repoFormatResult(repo) {
            if (repo == undefined || repo.loading == true) {
                return '<table class="table  table-bordered" style="padding: 0;margin: 0">' +
                    '<tr><td>车牌</td><td>车型</td><td>车主</td><td>手机号</td><td>门店</td></tr></table>';
            } else {
                return '<table class="table  table-bordered" style="padding: 0;margin: 0">' +
                    '<tr><td width="20%">'+repo.registerno+'</td><td width="20%" >'+repo.cmodel+'</td><td width="20%">'+repo.driver+'</td><td width="20%">'+repo.driverhandphone+'</td><td width="20%">'+repo.comno+'</td></tr></table>';
            }
        }
    
        function repoFormatSelection(repo) {
            if (repo.registerno) {
                vehicleData = repo; //赋值给当前车辆档案
                saveMember(repo.driverhandphone);
                return repo.registerno;
    
            }
        }
    

    保存的对象 没法表单提交

       delete vehicleData.element;
    

    设置多选例子

     $(".notify").select2({
         theme: "bootstrap",
         tags:["开单","结算","收银","回访","保险",]
     });
      multiple="multiple" //加上这属性 select

    相关文章

      网友评论

          本文标题:select2 搜索分页例子

          本文链接:https://www.haomeiwen.com/subject/lbpdzxtx.html