如何根据数据有条件地更改我的反应 table 访问器值?

How to I change my react table accesssor value based on data conditionally?

const data = {
    name:"test1",
    fclPrice:100,
    lclPrice:null,
    total:"50"
    }

和我的两个专栏:

const Datatable = [
  { Header: 'Name', accessor: 'name' }, 
  { Header: 'Price', accessor:'?' },
  { Header: 'Total', accessor:'total' }  
];

我希望访问者获取带有数字的价格密钥 例如:如果 fclprice:null 和 lclPrice:100 它应该采用 lclPrice,反之亦然

您可以将访问器的值设置为 function,它会将包含您的数据的对象作为第一个参数。然后,你可以传递任何你想要的条件:

const Datatable = [
  { Header: 'Price', accessor: (data)=>data.fclPrice || data.lclPrice},  
];