核心代码:
columns: [
{
checkbox:true //第一列显示复选框
},
...
{
field: \'fail_num\',
title: \'失败数\'
},
{
field: \'operate\',
title: \'操作\',
width: 120,
align: \'center\',
valign: \'middle\',
formatter: actionFormatter,
},
],
});
//操作栏的格式化,value代表当前单元格中的值,row代表当前行数据,index表示当前行的下标
function actionFormatter(value, row, index) {
var id = index;
var data = JSON.stringify(row);
var result = "";
result += "<a href=http://www.likecs.com/\'javascript:;\' class=http://www.likecs.com/\'btn btn-xs green\' onclick=http://www.likecs.com/\"EditViewById(\'" + id + "\', view=http://www.likecs.com/\'view\')\" title=http://www.likecs.com/\'查看\'><span class=http://www.likecs.com/\'glyphicon glyphicon-search\'></span></a>";
result += "<a href=http://www.likecs.com/\'javascript:;\' class=http://www.likecs.com/\'btn btn-xs blue\' onclick=http://www.likecs.com/\"EditViewById(\'" + row + "\',\'" + id + "\')\" title=http://www.likecs.com/\'编辑\'><span class=http://www.likecs.com/\'glyphicon glyphicon-pencil\'></span></a>";
result += "<a href=http://www.likecs.com/\'javascript:;\' class=http://www.likecs.com/\'btn btn-xs red\' onclick=http://www.likecs.com/\"DeleteByIds(\'" + id + "\')\" title=http://www.likecs.com/\'删除\'><span class=http://www.likecs.com/\'glyphicon glyphicon-remove\'></span></a>";
return result;
}
// getData方法获取全部页面数据后,将data转为json对象,使用index当前行号作为下标获取对应数据
function EditViewById(row, index){
var data = JSON.stringify($("#mytab").bootstrapTable(\'getData\')); //获取全部数据
var data_json = JSON.parse(data); //data_json和data_json2一样都是json对象
{#var data_json2 = eval("(" + data+ ")"); #}
console.log(data_json);
//由于data2已经是对象了,alert不能显示对象只能显示为[object Object],需要控制台打印
{#alert(data_json[0]); #}
//根据index找到对应行数据,填充数据到修改模态框
$("#update_submit_test_time").val(data_json[index].project_name);
$("#update_case_num").val(data_json[index].case_num);
$("#update_executed_num").val(data_json[index].executed_num);
$("#update_pass_num").val(data_json[index].pass_num);
$("#update_fail_num").val(data_json[index].fail_num);
//弹出修改模态框,非新增模态框
$(\'#updateModal\').modal(\'show\')
}