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,
}],
});
//对应的函数进行判断;
functionstateFormatter(value,row,index){
if(row.state==true)
return{
disabled:false,//设置是否可用
checked:true//设置选中
};
returnvalue;
}
模拟后台对应的数据;
[
{
"id":"1",
"name":"金蝶软件(中国)有限公司",
"state":false,//是否选中
"tel":"18536552258"
},
{
"id":"2",
"name":"金蝶软件(中国)有限公司",
"state":true,
"tel":"18536552258"
},
{
"id":"3",
"name":"金蝶软件(中国)有限公司",
"state":false,
"tel":"18536552258"
}
]
以上所述是小编给大家介绍的BootStrapTable复选框默认选中功能的实现代码(从数据库获取到对应的状态进行判断是否为选中状态),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!