table无法渲染,有数据

提问 未结 4 199
卡卡罗特qaq
悬赏:20飞吻
版本:layui 2.5.6 浏览器:谷歌 版本 80.0.3987.116(正式版本) (64 位)
table用的是方法渲染

html代码
<table id="table" lay-filter="table">

</table>
js代码
form.on('select(styleSelect)',function(data){
$.ajax({
type : "post",
contentType : "application/json; charset=utf-8",
dateType : "json",
data:JSON.stringify({CommodityBH:data.value}),
url : "/myerp/api/getCommodityColorSizeList",
success : function(res) {
console.log("res"+res);
console.log("res"+res.resultJson);

//表格
table.render({
elem:'#table',
url:'',
parseData:function(res){
return{
"code":res.code, //解析接口状态
"data":res.resultJson,
};
},

cols:[[
{field:'BH',title:'BH',width:60,sort:true,hide:true},
{field:'Color',title:'颜色',width:100,sort:true},
{field:'Size',title:'尺寸',width:100,sort:true},
/* {field:'PinAmount',title:"针数",width:100},
{field:'OrderAmount',title:"下单数量",width:100},*/
{field:'Unit',title:'单位',width:60}
/*{field:'DownWeight',title:"下机克重",width:100},
{field:'FinishedWeight',title:"成品克重",width:100},
{field:'Memo',title:"备注",width:500} */
]],

});
}
});
数据如下
{resultJson: [{"BH":61,"Size":"3-5","Color":"白色","Unit":"双"},{"BH":62,"Size":"3-5","Color":"黑色","Unit":"双"},{"BH":62,"8-10","Color":"红色","Unit":"双"}], code: 0, message: "查询成功", status: "0"}
回帖
  • IDyun
    2020-3-25
    赋值已知数据例子
    https://www.layui.com/demo/table/data.html
     table.render({ ,data: res.resultJson})
    0 回复
  • @IDyun 我的数据是通过ajax获取的,不是已知的数据,数据我是取到了,但是table里显示不出来
    0 回复
  • IDyun
    2020-3-26
    form.on('select(styleSelect)',function(data){
    table.reload('table',{url:'/myerp/api/getCommodityColorSizeList' ,where:{CommodityBH:data.value}});
    });

    //表格
    table.render({
    elem:'#table',
    method: 'post', //如果无需自定义HTTP类型,可不加该参数
    contentType: 'application/json; charset=utf-8',
    data:[],
    parseData:function(res){
    return{
    "code": res.code, //解析接口状态
    "msg": res.message, //解析提示文本
    "data":res.resultJson,
    };
    },
    cols:[[
    {field:'BH',title:'BH',width:60,sort:true,hide:true},
    {field:'Color',title:'颜色',width:100,sort:true},
    {field:'Size',title:'尺寸',width:100,sort:true},
    /* {field:'PinAmount',title:"针数",width:100},
    {field:'OrderAmount',title:"下单数量",width:100},*/
    {field:'Unit',title:'单位',width:60}
    /*{field:'DownWeight',title:"下机克重",width:100},
    {field:'FinishedWeight',title:"成品克重",width:100},
    {field:'Memo',title:"备注",width:500} */
    ]]
    });
    0 回复
  • @IDyun 直接报错了,这个报错也没看懂是什么意思
    0 回复