• select2 插件加载后端数据


    //html

      <select class="form-group form-control" name="roomId" id="roomList" data-op="eq" data-type="L" title="请选择租赁空间">
        <option value="">全部</option>
      </select>

    function selectRoomId(select) {
        $(select).select2({
            ajax: {
                url: webroot + "/spaceRoom/listRoom?buildingId=&floor=",
                dataType: 'json',
                delay: 250,
                data: function(params) {
                    var query = {
                        code: params.term
                    }
                    return query;
                },
                processResults: function(data, params) {
                    //请求接口返回数据
                    params.page = params.page || 1;
                    return {
                        results: data.result
                    };
                },
                cache: true
            },
            //options
            language: "zh-CN",
            placeholder: '请输入房间号',
            allowClear: true,
             '300px',
            //键盘选择事件
            escapeMarkup: function(markup) {
                return markup;
            },
            minimumInputLength: 1,
            templateResult: formatRepo,
            templateSelection: formatRepoSelection
        });
    }
    // 数据列表
    function formatRepo(repo) {
        if (repo.loading) {
            return repo.text;
        }
        var markup = "<div></div>";
        markup += "<div class='select2-result-repository clearfix'>" +
            "<div class='select2-result-repository__title'>" + repo.roomPath + "</div>";
        return markup;
    
    }
    //选择填入内容和返回字段
    function formatRepoSelection(repo) {
        return repo.text || repo.roomPath || repo.id;
    }

    //调用

    var roomIds = $('#roomList');
    selectRoomId(roomIds);

     

     //这里是post请求,传参为json(上面是get请求)

    function selectRoomId(select) {
        $(select).select2({
            ajax: {
                url: webroot + '/spaceRoom/listRoom',
                dataType: 'json',
                delay: 250,
                type:'POST',
                contentType: "application/json",
                data: function(params) {
                    var paramss = {
                        code: params.term
                    };
                    return JSON.stringify(paramss);
                },
                processResults: function(data, params) {
                    //请求接口返回数据
                    params.page = params.page || 1;
                    return {
                        results: data.result
                    };
                },
                cache: true
            },
            //options
            language: "zh-CN",
            placeholder: '请输入房间号',
            allowClear: true,
             '300px',
            //键盘选择事件
            escapeMarkup: function(markup) {
                return markup;
            },
            minimumInputLength: 1,
            templateResult: formatRepo,
            templateSelection: formatRepoSelection
        });
    }
    // 数据列表
    function formatRepo(repo) {
        if (repo.loading) {
            return repo.text;
        }
        var markup = "<div></div>";
        markup += "<div class='select2-result-repository clearfix'>" +
            "<div class='select2-result-repository__title'>" + repo.roomPath + "</div>";
        return markup;
    
    }
    //选择填入内容和返回字段
    function formatRepoSelection(repo) {
        return repo.text || repo.roomPath || repo.id;
    }
  • 相关阅读:
    zabbix监控之zabbix-agent被动变为主动,搭建Proxy代理
    zabbix监控nginx,mysql,java
    浅谈 HTTP协议
    ELK实时日志分析平台环境部署,以及可视化展示
    Shell脚本中$0、$?、$!、$$、$*、$#、$@的意义
    mfs分布式文件系统,分布式存储,高可用(pacemaker+corosync+pcs),磁盘共享(iscsi),fence解决脑裂问题
    Centos 或者 Redhat修改系统时间
    HTTPS加密协议过程
    实现mysql的读写分离(mysql-proxy)____1(mysql的主从复制,基于gtid的主从复制,半同步复制,组复制)
    实现mysql的读写分离(mysql-proxy)____2
  • 原文地址:https://www.cnblogs.com/Byme/p/8435753.html
Copyright © 2020-2023  润新知