当前位置: 首页 > 工具软件 > Select2 > 使用案例 >

Select2数据回显

谢志文
2023-12-01
    <select class="dggui-select" name="placeOrderUserId" id="placeOrderUserId">
    </select>

多选分页数据回显方式
初始化selet2

select2.render({
            elem: $('#placeOrderUserId'),
            placeholder: "选择下单人员",
            width: "200px",
            allowClear: true,
            ajax: {
                url: sysInfo.cmsBaseUrl + '/api/cms/user/v1/find_users.do?limit=10',
                dataType: 'json',
                data: function (params) {
                    var query = {
                        realName: params.term,
                        page: params.page || 1
                    }
                    return query;
                },
                processResults: function (data, params) {
                    var result = [];
                    if (data.data && data.data.data) {
                        $.each(data.data.data, function (i, n) {
                            result.push({'id': n.id, text: n.realName + '/' + n.loginName});
                        });
                    }
                    params.page = params.page || 1;
                    return {
                        results: result,
                        pagination: {
                            more: (params.page * 10) < data.data.recordsTotal
                        }
                    };
                }
            }
        });

数据回显

 		var value =[{id:8277,name:"哈哈哈"}];
        $.each(value, function (index, value) {
            $('#placeOrderUserId').append(new Option(value.name, value.id, false, true));
        });
        $('#placeOrderUserId').trigger("change");

select2普通多选回显:

  $('#placeOrderUserId').val([1,3]).trigger('change')
 类似资料: