layui表头自定义:拼接成功后赋值不了cols,一直赋值的是初始化的空值

讨论 已结
5 186
425607807_m
425607807_m 2018-10-11
悬赏:20飞吻
// 表格渲染
var colsList=[{field: 'COMP_NAME', title:'单位', width:160,align:'center',rowspan:2},{field:'BRAND_NAME',title:'卷烟品规',width:200,align:'center',rowspan:2}];
var dynamicCols=[];
var cols=[];
internalApi.getMarketingStrategyByMon(brandCode,fkRegularListUuid,reportType).done(function(rt){
if(rt.success){
var data = rt.data;
if(null !=data[0]){
if(data[0].jzweek-data[0].ksweek>=0){
for (var i = data[0].ksweek; i <= data[0].jzweek; i++) {
var info = { title:""+data[0].jzweek+"",align:'center'};
colsList.push(info);
}
}
cols.push(colsList)
}
if(null !=data[0]){
var info2 ="";
if(data[0].jzweek-data[0].ksweek>=0){
for (var i = data[0].ksweek; i <= data[0].jzweek; i++) {
var info2 = {field: 'salesnum'+data[0].ksweek, title: '实际销售量',align:'center'};
dynamicCols.push(info2);
}
}
cols.push(dynamicCols)
//alert(JSON.stringify(cols))
}
}
})

var gridConfig3 = {
elem: '#dTable3'
,width: ""
,height: "full-140"
,url:PATHS.internalPath+"superviseAnalysis/getMarketingStrategyByMonSqlStr.dobrandCode="+brandCode+"&fkRegularListUuid="+fkRegularListUuid+"&reportType="+reportType
,page: true //开启分页
,even: false //隔行背景
,cols: cols
,id: 'tableReload3'
};
回帖
  • IBean
    2018-10-12
    @425607807_m cols为空?internalApi这个是做了类似ajax的请求嘛?是的话把你的gridConfig3这个放到done回调里试过嘛?
    0 回复
  • 425607807_m
    2018-10-11
    都没人做过js拼接的layui动态表头吗
    0 回复
  • IBean
    2018-10-11
    做过,没有问题,还有你能用代码格式发吗。。这样好乱啊看着
    0 回复
  • 425607807_m
    2018-10-11
    @IBean 现在的问题是我初始化的cols=[];在上面的取值当中取到了正确的json串,但是自定义的cols的值赋不到table渲染当中,一直为空。已验证自定义的cols拷贝到table渲染当中是有表头的?
    0 回复
  • 425607807_m
    2018-10-12
    @IBean 感觉影响整个页面布局一直没往这方面想[ok]
    0 回复