reactjs - 对 MaterialTable 的常规反应表
问题描述
如何从数组中将数据添加到材料表中?
我有下表:
<table className="table">
<thead>
<tr>
<th>Text1</th>
<th>Text2</th>
<th>text3 Comb</th>
</tr>
</thead>
<tbody>
{arr.map((values, index) => {
const textComb = `${values.text1}, ${values.text2}`;
return (
<tr key={index}>
<td>{values.text1}</td>
<td>{values.text2}</td>
<td>{textComb}</td>
<td></td>
</tr>
)
})}
</tbody>
</table>
我有太多数据,所以我尝试使用 MaterialTable 来进行搜索、排序和分页选项。
<MaterialTable
columns={[
{title: 'Text1', field: 'text1'},
{title: 'Text2', field: 'text2'},
{title: 'Text3', field: 'text3'}
]}
data={
arr((values, index) => {
{
// I'm confused here
}
})
}
/>
解决方案
尝试这个-
const createData = item => ({
text1: item.text1,
text2: item.text2,
text3: `${item.text1}, ${item.text2}`
});
const data = arr.map(item => createData(item));
在此处查看演示 - https://codesandbox.io/s/material-table-example-5cohx?file=/src/App.js
推荐阅读
- python - 在另一个 python 文件中关闭一个 python 文件
- c++ - 编写一个只接受字面量 `0` 或字面量 `1` 作为参数的函数
- c# - 将数组转移到 main 方法
- java - 如何在 RecyclerView 的所有项目中显示此复选框?
- android-activity - 如何在活动图中表示实现接口
- spring-boot - 本地 docker 服务的 Spring Boot Kafka 连接问题
- linux - NASM、TASM 和 MASM 之间的区别
- nginx - Nginx 跨域请求被阻止
- android - 单击选项卡时如何平滑滚动到我的回收站视图中的标题
- mysql - MySQL 查询中的 SQL NOT BETWEEN 语法