如何在智能的一行中显示一个对象table
how to display an object in one row of smart table
我想在 table.
的一种情况下显示这 3 个属性“currencyCode
、Amount
、serialData
”
我正在使用 ng2-smart-table 和 angular 11
我正在尝试这段代码,但没有任何效果
dateTime: {
title: 'Date & Time',
},
montant: {
title: 'Montant',
},
serialNbr: {
title: 'serialNbr',
CurrencyCode: {
valuePrepareFunction: (row) => { return row.serialNbr.CurrencyCode }
},
Amount: {
valuePrepareFunction: (row) => { return row.serialNbr.Amount }
},
SerialData: {
valuePrepareFunction: (row) => { return row.serialNbr.SerialData }
},
},
根据文档
valuePrepareFunction - function run against a value before it gets inserted into a cell. You can use it to modify how a value is displayed in the cell.
This function will be invoked with 2 parameters: cell, row
Documentation
我认为您应该更改以下代码
serialNbr: {
title: 'serialNbr',
valuePrepareFunction: (cell, row) => {
return `${row.serialNbr.CurrencyCode} ${row.serialNbr.Amount } ${row.serialNbr.SerialData }`
},
},
我完美地解决了我的问题并且我分享了这段代码来帮助其他人遇到同样的问题,如果你有一个嵌套字段或一个对象数组的字段
dateTime: {
title: 'Date & Time',
},
montant: {
title: 'Montant',
},
serialNbr: {
title: 'Serial Number',
valuePrepareFunction: (serialNbr) => {
return serialNbr.map(s => "" + s.CurrencyCode + ","+s.Amount+","+s.SerialData+" ").toString()
}
},
我想在 table.
的一种情况下显示这 3 个属性“currencyCode
、Amount
、serialData
”
我正在使用 ng2-smart-table 和 angular 11 我正在尝试这段代码,但没有任何效果
dateTime: {
title: 'Date & Time',
},
montant: {
title: 'Montant',
},
serialNbr: {
title: 'serialNbr',
CurrencyCode: {
valuePrepareFunction: (row) => { return row.serialNbr.CurrencyCode }
},
Amount: {
valuePrepareFunction: (row) => { return row.serialNbr.Amount }
},
SerialData: {
valuePrepareFunction: (row) => { return row.serialNbr.SerialData }
},
},
根据文档
valuePrepareFunction - function run against a value before it gets inserted into a cell. You can use it to modify how a value is displayed in the cell. This function will be invoked with 2 parameters: cell, row Documentation
我认为您应该更改以下代码
serialNbr: {
title: 'serialNbr',
valuePrepareFunction: (cell, row) => {
return `${row.serialNbr.CurrencyCode} ${row.serialNbr.Amount } ${row.serialNbr.SerialData }`
},
},
我完美地解决了我的问题并且我分享了这段代码来帮助其他人遇到同样的问题,如果你有一个嵌套字段或一个对象数组的字段
dateTime: {
title: 'Date & Time',
},
montant: {
title: 'Montant',
},
serialNbr: {
title: 'Serial Number',
valuePrepareFunction: (serialNbr) => {
return serialNbr.map(s => "" + s.CurrencyCode + ","+s.Amount+","+s.SerialData+" ").toString()
}
},