Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

ant design表格render函数中text和record参数的区别?

函数说明
renderfunction(text, record, index)生成复杂数据的渲染函数,参数分别为当前行的值,当前行数据,行索引,

text和record分别是什么?为什么我打印出来的结果一样?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

给你举个例子:

import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Table } from "antd";
const columns = [
  {
    title: "Name",
    dataIndex: "name",
    render: (text, row, index) => {
      console.log(text, row);
      if (index < 4) {
        return <a>{text}</a>;
      }
      return {
        children: <a>{text}</a>,
        props: {
          colSpan: 5
        }
      };
    }
  },
];

const data = [
  {
    key: "1",
    name: "John Brown",
    age: 32,
    tel: "0571-22098909",
    phone: 18889898989,
    address: "New York No. 1 Lake Park"
  }
];

ReactDOM.render(
  <Table columns={columns} dataSource={data} bordered />,
  document.getElementById("container")
);

上面代码中对应的text为John Brown;而 record为{key: "1",name: "John Brown",age: 32,tel: "0571-22098909",phone: 18889898989,address: "New York No. 1 Lake Park"}

如果你说两个一样,就得看你的代码是怎么写的了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...