大红色的将军

Django bootstrap-select 多选框显示以及回显

初始化

function showUserList(param) {
    $.ajax({
        url: "user/detail/0/",
        type: 'get',
        success: function (data) {
            $('#' + param).empty();
            for (var i = 0; i < data.length; i++) {
                op = "<option value=" + data[i].id + ">" + data[i].first_name + "[" + data[i].username + "]" + "</option>";
                $('#' + param).append(op);
            }
            $('#' + param).selectpicker('refresh');
            $('#' + param).selectpicker('render');
        }
    })
}

回显

//回显校区详情页面信息
function editCampussInfo(id) {
    var result = getCamPuss(id);
    $('#editcname').val(result.cname);
    $('#editarea').val(result.area);
    $('#editmark').val(result.mark);
    $('#editid').val(id);
    leaderlist = result.leader.split(',')
    $.ajax({
        url: "user/detail/0/",
        type: 'get',
        success: function (data) {
            $('#editleader').empty();
            for (var i = 0; i < data.length; i++) {
                op = "<option value=" + data[i].id + ">" + data[i].first_name + "[" + data[i].username + "]" + "</option>";
                $('#editleader').append(op);
            }
            $('#editleader').selectpicker('val',leaderlist);
            $('#editleader').selectpicker('refresh');
            $('#editleader').selectpicker('render');
        }
    })
}

 

posted @ 2018-09-25 23:47  欧德派  阅读(1872)  评论(0编辑  收藏  举报