Javascript 如何连接材质表中的两个或多个字段
我试图在我的material表中创建一个“Name”列,其中包含来自数组的串联的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
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',
},