字段为空时,怎么给默认的字符串,我下面的备注,和戚薇字段,有时为null ,想给默认的字符串,如‘暂无’之类的 ,且加样式,也加不上去
const columns = [
// {
// key: 'selection',
// width: 50,
// cellRenderer: ({ rowData }) => {
// const onChange = (value: CheckboxValueType) => (rowData.checked = value)
// return <SelectionCell value={rowData.checked} onChange={onChange} />
// },
// },
{
key: "profilePhoto",
dataKey: "profilePhoto",//需要渲染当前列的数据字段,如{id:9527,name:'Mike'},则填id
title: "头像",//显示在单元格表头的文本
width: 160,//当前列的宽度,必须设置
fixed: false,//是否固定列
cellRenderer: ({ cellData }) =>
h(
'img',
{ src: cellData },
),
},
{
key: "name",
dataKey: "name",//需要渲染当前列的数据字段,如{id:9527,name:'Mike'},则填name
title: "昵称",
width: 200,
fixed: false,
},
{
key: "alias",
dataKey: "alias",
title: "备注",
width: 200,
},
{
key: "company",
dataKey: 'company',
title: "个人/企微",
// minWidth: 100,
width: 200,
cellRenderer: ({ cellData }) => {
h(
'div',
{ class: 'dasdf' },
{ default: () => 'cellData' }
)
}
}
];
你这个应该是 封装组件的时候,循环了这个colums 数组,自动生成一个表格。假设你需要设置默认值,只需要在v-for 循环的地方,判断是否存在 title 属性对应的值,如果不存在就指定一个 默认值就行。用三元运算符
cellRenderer 里可以做判断 把写个 三目 不同的值 给 不同 的 h()方法