【问题标题】:Add onclick event to material table react js将onclick事件添加到材料表反应js
【发布时间】:2021-08-30 17:28:23
【问题描述】:

我需要从服务器检索数据,然后将这些数据显示在表格中,如果用户单击表格中的按钮,他可以下载文件

这是我的数据:

files = [ {name : "file1", created_at: "29/01/2021"},
          {name : "file2", created_at: "20/03/2021"}]

表格标题:

const tableColumns = [
  { title: "name", field: "name" },

  {
    title: "Date",
    field: "created_at",
    type: "date",
    dateSetting: { locale: "en-GB" },
    filterComponent: (props) => <CustomDatePicker {...props} />
  }
];

我的数组:

{file && (
<Fragment>
<MaterialTable
columns={tableColumns}
data={file}
title="Material Table - Custom Filter Component"
options={{search: false, filtering: true }}

actions={[
  {
    icon: 'save',
    tooltip: 'Save User',
    onClick: () => window.open('http://localhost:5000/files/' + file.name, '_blank').focus()
  }
]}
/>
</Fragment>)}

我收到错误:ENOENT: no such file or directory, stat '/Users/admin//files/undefined'"}

如何在 react js 中使用每个文件的链接,我尝试在我的数据上使用 map 函数但它不起作用

【问题讨论】:

  • 嘿@Cissus 我刚刚回答了这个here。

标签: reactjs onclick material-table


【解决方案1】:

即使它可以在您的计算机上运行,​​该代码也无法在公共服务器上运行。因为没人知道http://localhost:5000是什么。

为了让这条线路正常工作,您需要找到可以在浏览器中访问的资源,例如。 google.com

然后试一试,看看你是否仍然遇到这个错误。

注意:网站等客户端应用程序无法处理您计算机中的物理文件。这是不允许的,但是一旦你发布到网络上,它就会变成另一个可以存储文件的 URL。

【讨论】:

  • @windmaomo 这不是问题,我有一个允许从服务器获取文件的 api,但问题是如何在对象中添加链接
  • 在对象中添加链接是什么意思,您是否在问题描述中描述了这个问题?
  • 是的,我想添加一个指向对象的链接
  • 喜欢这个文件 = [ {name : "file1", created_at: "29/01/2021", link : "localhost:5000/files' + file.name"}],
猜你喜欢
  • 2021-07-16
  • 2021-10-26
  • 2022-06-30
  • 2017-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多