Terryzjh 2021-09-23 18:45 采纳率: 100%
浏览 196
已结题

react如何将后端给的数据渲染至表格中(后端的接口字段我放在评论区了)


import { Table } from "antd";
import React from "react";

export class Tables extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    const columns = [
      {
        title: '姓名',
        dataIndex: 'name',
        align: 'center',
      },
      {
        title: '电话',
        dataIndex: 'tel',
        align: 'center',
      },
      {
        title: '地址',
        dataIndex: 'address',
        align: 'center',
      },
      {
        title: '邮箱',
        dataIndex: 'email',
        align: 'center',
        render: (text,r) => <a href={"www.baidu.com"+r.key} target="_blank">{text}</a>,
      },
    ];

    const data = [
      {
        key: '1',
        name: 'John Brown',
        tel: '10086',
        address: '成都',
        email: '103685334@qq.com',
      },
      {
        key: '2',
        name: 'Jim Green',
        tel: '1008611',
        address: '上海',
        email: '',
      },
      {
        key: '3',
        name: 'Joe Black',
        tel: '10001',
        address: '深圳',
        email: '',
      },
    ];
    return (
      <Table
        columns={columns}
        dataSource={data}
        bordered
      />
    )
  }
}
  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月4日
  • 已采纳回答 9月26日
  • 创建了问题 9月23日

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程