多選下拉框xmSelect

qq_45473377發表於2020-12-24

效果圖

在這裡插入圖片描述

Html

 <div class="layui-inline">
      <div id="payedEnum" class="xm-select-demo" style="width: 100%;display: inline-block;padding-right: 60px"></div>
</div>

js

引入xmSelect控制元件(使用的的layui的前端框架,專案匯入xmSelect檔案後配置vision 指向xmSelect地址,封裝進layui後直接use)

layui.use(['table', 'jqbind','form','laydate','roomsearch','xmSelect'], function () {
var xmSelect=layui.xmSelect;
}

靜態渲染data

var structureIdSelect = xmSelect.render({
        el: '#payedEnum',
        name: 'payedEnum',
        data: [
            {"name":"未支付","value":0},
            {"name":"部分支付","value":1},
            {"name":"已結清","value":2}
        ],
        tips:"支付狀態",
        autoRow: true
    });

動態渲染data

var structureIdSelect = xmSelect.render({
            el: '#payedEnum',
            name: 'payedEnum',
            data: []
        });

        $.ajax({
            type: "GET",
            url: "v3/charge/getAllPayedEnum",
            dataType: "json",
            success: function(res){
                structureIdSelect.update({
                    data: res.data,
                    autoRow: true,
                })
            }
        });

向後臺傳遞引數是一個string字串"0,1"

相關文章