ReactJs"不变违规......"经典反应问题

Fra*_*ard 7 reactjs

这是一个典型的反应问题,但我有点不知道如何处理它.我只是想动态渲染我的表格行但是我得到错误:""未捕获错误:不变违规:processUpdates():无法找到元素的子元素2.这可能意味着DOM意外地发生了变异(例如,通过浏览器),通常是由于在使用表时忘记了一个,嵌套标签如,

,或,或在父母中使用非SVG元素.尝试使用React ID检查元素的子节点.2.1.0."

我理解反应是找不到合适的DOM东西但是如何处理呢?提前致谢 !

<div className="panel-body" style={panelstyle}>
              <Table striped bordered condensed hover>
                <thread>
                  <th> Currency </th>
                  <th> Amount </th>
                  <th> Issuer </th>
                  <th> Limit </th>
                  <th> Limit Peer </th>
                  <th> No-Ripple </th>
                </thread>
                <tbody>
                  {this.state.ripplelines[this.address] ?

                              this.state.ripplelines[this.address].lines.map(function(line,i) {

                            return      (<tr>
                                          <td> USD </td>
                                          <td> 1500 </td>
                                          <td> raazdazdizrjazirazrka?rkazrâkrp </td>
                                          <td> 1000000000 </td>
                                          <td> 0 </td>
                                          <td> True </td>
                                        </tr>)       
                            ;
                        })             
                  : ""}
                </tbody>
              </Table>
            </div>
Run Code Online (Sandbox Code Playgroud)

Fra*_*ard 5

这里有一个答案:React js: Invariant Violation: processUpdates() when render a table with a different number of child rows

只需在渲染前准备好行即可!

render:
 var rows = [];
      if(this.state.ripplelines[this.address] ) {
        _.each(this.state.ripplelines[this.address].lines, function(line) {
           rows.push(                   <tr>
                                          <td> somestuff!</td>

                                        </tr>)
        }); 
      }
return (
    <Table striped bordered condensed hover>
                    <thead>
                      <th> Currency </th>
                      <th> Amount </th>
                      <th> Issuer </th>
                      <th> Limit </th>
                      <th> Limit Peer </th>
                      <th> No-Ripple </th>
                    </thead>     
                    <tbody>
                      {rows}    
                    </tbody>
              </Table>
)
Run Code Online (Sandbox Code Playgroud)