简体   繁体   English

如何在智能表的一行中显示 object

[英]how to display an object in one row of smart table

来自 MongoDB 的实体 在此处输入图像描述

I want to display those 3 attributes " currencyCode , Amount , serialData " in one case of table.我想在一个表的情况下显示这 3 个属性“ currencyCodeAmountserialData ”。

I'm using ng2-smart-table with angular 11 and I'm try this code but nothings work我将 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 } }, },

According to the documentation根据文档

valuePrepareFunction - function run against a value before it gets inserted into a cell. valuePrepareFunction - function 在将值插入单元格之前对其运行。 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此 function 将使用 2 个参数调用:单元格、行文档

I think you should change your code in the following我认为你应该在下面更改你的代码

    serialNbr: {
        title: 'serialNbr',
         valuePrepareFunction: (cell, row) => {
           return `${row.serialNbr.CurrencyCode} ${row.serialNbr.Amount } ${row.serialNbr.SerialData }` 
        },
      },

i fix my issue perfectly and i share this code to help anyone else have the same problem, if you have a nested field or a field that is an array of objects我完美地解决了我的问题,如果您有一个嵌套字段或一个对象数组的字段,我会分享此代码以帮助其他任何人遇到同样的问题在此处输入图像描述

 dateTime: { title: 'Date & Time', }, montant: { title: 'Montant', }, serialNbr: { title: 'Serial Number', valuePrepareFunction: (serialNbr) => { return serialNbr.map(s => "" + s.CurrencyCode + ","+s.Amount+","+s.SerialData+" ").toString() } },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM