layui.table 渲染时如何处理 null 或 undefined
使用 templet 自定义模板函数,在返回内容前判断字段值是否为空。如果值为 null 或 undefined,则返回空字符串或占位符,否则返回原始数据。

通过 parseData 预处理接口数据
在表格配置中设置 parseData 回调函数,将接口返回的 null 统一转换为空字符串或其他默认值。这样后续所有列都可以直接使用默认渲染逻辑,无需逐个处理。

特定列使用 templet 的详细写法
对于需要特殊处理的列,可以在 cols 配置中使用 templet 属性。例如,当某列为 name 时,若其值为 null,则显示为 -;若为 undefined,则显示为空。
{
cols: [[
{field: 'name', title: '姓名', templet: function(d) {
return d.name == null ? '-' : d.name;
}},
{field: 'age', title: '年龄'}
]]
}











