本人微信公众号"aeolian"~

动态生成多选框

后台

    /**
     * 获取所有角色
     * @return
     */
    @RequestMapping("getAllRole")
    @ResponseBody
    public List getAllRole(){
        List result = roleService.getAllRole();
        return result;
    }

前端JS

function loadRoleChk(url,tag_id){
    $.ajax({
                 url:url,    
                 dataType:'json',
                 data:{},
                 type:'post',
                 success:function(data){
                var options="";   //字符串拼接
                for(var i in data){  //遍历json数组
                    options += ""+data[i].rolename+"  "
                }
                $('#'+tag_id).empty();
                $('#'+tag_id).html(options);
                 },
                 error:function(){}
           });
}

调用

$(function(){
loadRoleChk("/${appName}/manager/roleController/getAllRole","roleAccess");
});

HTML

<div class="form-group">
    <label class="col-sm-3 control-label">
        所属角色:
    label>
    <div class="col-sm-8 controls" id='roleAccess'>
    div>
div>

 

点赞

Leave a Reply

Your email address will not be published. Required fields are marked *