这次在开发中遇到,有列数不固定的情况。废话不多说,先上图,在上代码。
下面上JS代码
function SearchData() {
var dYear = $("#DYear").val();
var beginWeek = $("#DSWeek").val();
var endWeek = $("#DEWeek").val();
var params = {};
params = CreateParamData(params, "dYear", dYear);
params = CreateParamData(params, "beginWeek", beginWeek);
params = CreateParamData(params, "endWeek", endWeek);
var mycars = new Array();
var result;
$.ajax({
url: GetUrl('Mold', 'Mold_MaintTotal'), // //请求路径
type: "post",// "post", //请求方式
dataType: 'json', //期望获得的返回值类型
async: false, //是否异步
data: params, //传递的参数
success: function (data) {
console.log(data.Data);
if (data != '') {
if (data.Result == 3) {
result = data.Data;
var strs = new Array();
strs = result[0];
for (var k in strs) {
mycars.push({
field: k, title: k, align: 'center', width: 120, sort: false
});
}
}
}
},
error: function (jqXHR, textStatus, errorThrown) { //console.log('状态码:' + jqXHR.status);
//console.log('错误信息:' + jqXHR.statusText);
//console.log('服务器反馈信息:' + textStatus);
}
});
layui.use(['form', 'layer', 'table', 'jquery'],
function () {
var laytable = layui.table; //动态加载数据
laytable.render({
elem: '#workbTable'
, cols: [mycars]
, data: result
});
});
};