我有兩個(gè)數(shù)組,1 列和 2 行。我想按照代碼中所示動(dòng)態(tài)地將行數(shù)組數(shù)據(jù)添加到列數(shù)組。暫時(shí)我在這些數(shù)組中采用了硬編碼值,我有一個(gè)添加按鈕。實(shí)際上我想渲染具有下拉按鈕的 n*n 矩陣。我在添加按鈕上定義了一種方法,并使用 for 循環(huán)將列數(shù)組推送到行數(shù)組。import React, { Component } from "react";import './Table.css';export class Table extends Component { constructor(props) { super(props) this.state = { columns: ['state 1', 'state 2', 'state 3', 'state 4', 'state 5', ''], emptyheader: [''], rows: [ ['state 1', 'state 2', 'state 3', 'state 4', '', ''], ['state 2', 'state 2', 'state 3', 'state 4', ' ', ''], ['state 3', 'state 2', 'state 3', 'state 4', ' ', ''], ['state 4', 'state 2', 'state 3', 'state 4', ' ', ''], ['state 5', 'state 2', 'state 3', 'state 4', ' ', ''] ], selectedTeam: '' } this.handleChange = this.handleChange.bind(this) } render() { return ( <div> <table align="center"> <tbody> <tr> {this.state.emptyheader.map((emptyheader, i) => <td >{emptyheader}</td> )} {this.state.columns.map((column, i) => <td >{column}</td> )} </tr>export default Table;我想渲染 n*n 矩陣
我想以以下格式動(dòng)態(tài)添加數(shù)組中的元素
梵蒂岡之花
2021-10-14 17:19:31