这是一个典型的 react 问题,但我有点不知道如何处理它。 我只想动态渲染我的表格线,但我收到错误:” “未捕获错误:不变违规:processUpdates():无法找到元素的子元素 2。这可能意味着 DOM 意外变异(例如,由浏览器),通常是由于在使用表、嵌套标签(例如 , )时忘记了 a p>
或 ,或在父级中使用非 SVG 元素。尝试使用 React ID .2.1.0
检查该元素的子节点。"
我知道 React 没有找到正确的 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>
最佳答案
只需在渲染之前准备好行即可!
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>
)
关于ReactJs "Invariant violation..."经典 react 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29123560/