将2个字段传递到标题中的键,React-CSV

发布于 2025-02-08 04:37:32 字数 1472 浏览 1 评论 0原文

与现有问题有关。 -csv 。我正在做一些事情,遇到了同一问题。再次询问,因为没有正确的答案。 标题的以下代码。 - 键:“ user.firstname + user.lastName”不起作用,并且字段为空。请帮助如何使此工作! tia!

代码:

headers = [
{
  label: "id",
  key: "user.id"
},
{
  label: "Agent Name",
  key: "user.firstName + user.lastName"
},
{
  label: "Agent Email",
  key: "user.email"
},
{
  label: "Agent Phone",
  key: "user.phoneNumber"
},
{
  label: "Agent Commission",
  key: "agentComission"
},
{
  label: "Company Commission",
  key: "companyComission"
},
{
  label: "Total Sale",
  key: "sale"
}
];

数据格式示例:

data = [
  {
    id: 1,
    firstnamename: "name ",
    lastname: "lastname",
    email: "[email protected]",
    phoneNumber: 123456789,
    agentComission: 'agent comission',
    companyComission: 'company comission',
    sale: 'sale',
  },
  {
    id: 2,
    firstnamename: "name",
    lastname: "lastname,
    email: "[email protected]",
    phoneNumber: 123456789,
    agentComission: 'agent comission 2',
    companyComission: 'company comission 2',
    sale: 'sale 2',
  },
];

Related to the existing question. How to assign two fields data in header of react-csv. I am working on something and came across the same issue. Asking again since there is no correct answer given. The following code for headers. - key: "user.firstname + user.lastname" doesn't work and the fields are empty. Please help how to get this working! TIA!!

Code:

headers = [
{
  label: "id",
  key: "user.id"
},
{
  label: "Agent Name",
  key: "user.firstName + user.lastName"
},
{
  label: "Agent Email",
  key: "user.email"
},
{
  label: "Agent Phone",
  key: "user.phoneNumber"
},
{
  label: "Agent Commission",
  key: "agentComission"
},
{
  label: "Company Commission",
  key: "companyComission"
},
{
  label: "Total Sale",
  key: "sale"
}
];

Data format example :

data = [
  {
    id: 1,
    firstnamename: "name ",
    lastname: "lastname",
    email: "[email protected]",
    phoneNumber: 123456789,
    agentComission: 'agent comission',
    companyComission: 'company comission',
    sale: 'sale',
  },
  {
    id: 2,
    firstnamename: "name",
    lastname: "lastname,
    email: "[email protected]",
    phoneNumber: 123456789,
    agentComission: 'agent comission 2',
    companyComission: 'company comission 2',
    sale: 'sale 2',
  },
];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文