我需要从服务器获取数据,然后我在表格中显示这些数据(反应 js),如果用户点击表格中的按钮,他可以下载文件
<Table>
<thead>
<tr>
<th>File Name</th>
<th>Date</th>
<th>Download file</th>
</tr>
</thead>
{files && (
<tbody className="text-content-dark">
{files.map(file => (
<tr>
<td>{file.name}</td>
<td>{file.date}</td>
<td>
<Button
className="btn-large btn-primary fit-content"
icon="arrowRight"
iconPosition="right"
onClick={() => window.open('http://localhost:5000/files/' + file.name, '_blank').focus()}>
Download
</Button>
</td>
</tr>
))}
</tbody>
)}
</Table>
现在我想使用材料表,但我没有找到将链接添加到每个数据对象示例的方法:
files = [ {name : "file1", created_at: "29/01/2021", link : "localhost:5000/files" + "file1"},
{name : "file2", created_at: "20/03/2021",link : "localhost:5000/files" + "file2"}]
材料表:
{files && (
<Fragment>
<MaterialTable
columns={tableColumns}
data={files}
title="Material Table - Custom Filter Component"
options={{ search: false, filtering: true }}
actions={[
{
icon: 'save',
tooltip: 'Save User',
onClick: () => window.open('http://localhost:5000/files/' + files.name, '_blank').focus()
}
]}
/>
</Fragment>)}
但我得到错误文件未定义;
