首页 > 解决方案 > 如何在 React 中将状态传递给 MDBDataTable

问题描述

我对 React 有疑问。我需要将一个对象传递给 React,<MDBDataTable>但数据处于状态。关于如何实现这一目标的任何想法?

数据必须像这样传递

<MDBDataTable className="text-center" striped hover bordered small data={this.state}

我的状态看起来像这样

this.state = {
      column: [
        {
          id: 'id'
        },
        {
          serialNumber: 'sn'
        },
        {
          name: 'yr'
        }
      ],
      rows: null
    };

行默认为空,并使用此代码添加

this.setState({rows: data.map(u => ({
  id: u.id,
  serialNumber: u.login,
  yearRange: u.firstName
}))});

当我console.log(this.state)显示它应该的状态时。两者columnrows填充了数据

标签: reactjs

解决方案


推荐阅读