【问题标题】:Is there any way to add rows to a dynamic table in ReactJS?有没有办法在 ReactJS 中向动态表中添加行?
【发布时间】:2021-12-18 17:50:21
【问题描述】:

我有一个这样生成的表:

//xx = the number of rows xx3= the cells within each row
<tbody>    
                {this.state.data.map((data)=> {
                  let xx = data.players[2];
                    
                  let xx3 = xx.map((keys) =>{
                    return (<tr className='dataRow'>{keys.map((keys)=>{
                      return(<td><div contenteditable='true' id="editor"><input type="hidden" 
                      name={'1'} value={keys}/>{keys}</div></td>)})}</tr>) 
                  })  
                  
                  return(xx3);
                }
                )}           
</tbody>

我想制作一个按钮,点击时会在表格中添加一行。

我想我必须用 xx.push(['','','',...]) 之类的东西修改 xx 变量


有人知道如何做到这一点吗? (请考虑我对此很陌生)
谢谢。

【问题讨论】:

    标签: reactjs html-table


    【解决方案1】:

    您需要使用 setState。请至少阅读 React 文档的基础知识:https://reactjs.org/docs/state-and-lifecycle.html

    【讨论】:

      猜你喜欢
      • 2019-06-24
      • 1970-01-01
      • 2021-05-24
      • 2020-03-20
      • 2021-10-17
      • 2011-01-25
      • 2021-09-11
      • 1970-01-01
      • 2020-10-28
      相关资源
      最近更新 更多