初始化数组时,有时候不确定是否存在某个元素,数组的长度不确定,需要依据相应值来判断。
例如:
a = [1, 2, ...(flag ? [] : [3]) ]
// 当flag为true时,a = [1, 2];
// 当flag为false时,a = [1, 2, 3];
this.columnDefs = [
{
field: 'type',
headerName: this.translateService.instant('dj-default-类别'),
hide: false,
width: 95,
valueFormatter: this.typeTranslate.bind(this),
},
...(this.validateForm.get('open_stage').value !== '0'?[]:[
{
field: 'bom_seq',
headerName: this.translateService.instant('dj-default-BOM序号'),
hide: false,
width: 90,
}
]),
{
field: 'component_no',
headerName: this.translateService.instant('dj-default-元件品号'),
hide: false,
width: 130,
},
];