bootstrap-table复选框默认选中。(从数据库获取到对应的状态进行判断是否为选中状态)

$('#table').bootstrapTable('destroy'); 
$('#table').bootstrapTable({
url:'../data/kehulist.json',
uniqueId: "id",
striped:true,
// pagination:true,
clickToSelect:true,
height:340,
   columns: [ {
    field : 'state',
    checkbox:true, 
    formatter : stateFormatter
   }
,{
       field: 'id',       
       title: '组织编码',
       sortable: true,
   },{
       field: 'name',
       title: '组织名称',
       sortable: true,
   }],
});

/ /对应的函数进行判断;
function stateFormatter(value, row, index) {
    if (row.state == true)
        return {
            disabled : false,//设置是否可用
            checked : true//设置选中
        };
    return value;

}


模拟后台对应的数据;

[
    {   
        "id": "1",
        "name": "金蝶软件(中国)有限公司",
        "state": false,  //是否选中
        "tel":"18536552258"
    },
    {
        "id": "2",
        "name": "金蝶软件(中国)有限公司",
        "state": true,
        "tel":"18536552258"
    },
    {
        "id": "3",
        "name": "金蝶软件(中国)有限公司",
        "state": false,
        "tel":"18536552258"
    }
]

你可能感兴趣的:(bootstrap-table复选框默认选中。(从数据库获取到对应的状态进行判断是否为选中状态))