function () { var questionColumns=[]; $.ajax({ url: basePath + "ByStudentId.do", //请求后台的URL(*) type:'post', async:true, data:{classId:classId}, dataType:'json', success:function(data){ var data=data.rows; var jsonObject=data[0]; for(var key in jsonObject){ var titleValue=""; if(key=='studentId'){ titleValue='序号'; }else if(key=='examineeId'){ titleValue='考生编号'; }else if(key=='studentName'){ titleValue='考生姓名'; }else if(key.indexOf("studentScore")>0){ titleValue='知识点'+key.substring(12,key.length); }else{ titleValue='知识点'+key.substring(12,13); } var temp={width:"10%",field:key,title:titleValue,align:"center"};//手动拼接columns questionColumns.push(temp); } $('#studentKnowledgeScoreTable').bootstrapTable('destroy'); $('#studentKnowledgeScoreTable').bootstrapTable({ url: basePath + "ByStudentId.do", //请求后台的URL(*) method: 'post', //请求方式(*) classes: 'table table-hdgw', //toolbar: '#toolbar', //工具按钮用哪个容器 striped: true, //是否显示行间隔色 cache: false, //是否使用缓存,默认为true,所以 pagination: false, sortable: false, //是否启用排序 sortOrder: "asc", //排序方式 queryParamsType: "limit", contentType: "application/x-www-form-urlencoded",//请求数据内容格式 默 queryParams: {classId:classId},//传递参数(*) sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*) strictSearch: true, clickToSelect: true, //是否启用点击选中行 width:600, height: 350, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度 uniqueId: "recordId", //每一行的唯一标识,一般为主键列 cardView: false, //是否显示详细视图 detailView: false, //是否显示父子表 **columns:questionColumns** }); } }); //我用到的思想就是手动拼接一个columns的数组[]
https://zhidao.baidu.com/ques...