Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何连接材质表中的两个或多个字段_Javascript_Reactjs_Api_Rows_Material Table - Fatal编程技术网

Javascript 如何连接材质表中的两个或多个字段

Javascript 如何连接材质表中的两个或多个字段,javascript,reactjs,api,rows,material-table,Javascript,Reactjs,Api,Rows,Material Table,我试图在我的material表中创建一个“Name”列,其中包含来自数组的串联的firstname,lastname,但它每个字段只接受一个数据 有什么建议或帮助使之成为可能吗 const客户端={ 名字:“特蕾西”, 姓:“桑托斯”, 地址:{ 地址1:“马尼拉”, 地址2:“菲律宾”, } } 常量列=[ {title:'Name',field:'client.firstname'+'+'client.lastname'}, {title:'Address',field:'client.Ad

我试图在我的material表中创建一个“Name”列,其中包含来自数组的串联的
firstname,lastname
,但它每个字段只接受一个数据

有什么建议或帮助使之成为可能吗

const客户端={
名字:“特蕾西”,
姓:“桑托斯”,
地址:{
地址1:“马尼拉”,
地址2:“菲律宾”,
}
}
常量列=[
{title:'Name',field:'client.firstname'+'+'client.lastname'},
{title:'Address',field:'client.Address.address1'+''+'client.Address.address2'},
]

您的列需要有数据对象中存在的
字段

因此,将
对象更改为:

const列=[
{title:'Name',field:'fullName'},
{title:'Address',field:'fullAddress'},
];
一旦有了这些列,就需要修改传递到组件中的数据

const客户端={
名字:“特蕾西”,
姓:“桑托斯”,
地址:{
地址1:‘马尼拉’,
地址二:菲律宾,
}
}
//创建新对象
常数newData={
全名:`${client.firstname}${client.lastname}`,
fullAddress:“${client.address.address1},${client.address.address2}”,
};
然后,您可以将数据传递到表:

<MaterialTable columns={columns} data={newData} />

不需要修改传递给表的数据的另一种方法是为该字段使用自定义呈现函数

{
  render: (client) => {
    return `${client.firstName} ${client.lastName}`;
  },
  title: 'Client',
},

字段
属性在数据对象中查找特定键,而不查找数据值本身。您应该更新数据以包含这样一个新字段,并用名字和姓氏的组合填充它。
{
  render: (client) => {
    return `${client.firstName} ${client.lastName}`;
  },
  title: 'Client',
},