我正在开发一个 react - rails 应用程序,但我的控制台中一直出现此错误:
```
Warning: validateDOMNesting(...): <th> cannot appear as a child of <thead>.
See (unknown) > thead > th.
我不确定为什么这不起作用..我想为表格使用标题 (thead),它对其他人有效。我会放 tbody,但我需要它作为 table 的实际主体。
这是我的表格代码:
```
React.DOM.table
className: 'table table-bordered'
React.DOM.thead null,
React.DOM.th null, 'Description'
React.DOM.th null, 'Actions'
React.DOM.tbody null,
for post in @state.posts
React.createElement Post, key: post.id, post: post,
handleDeletePost: @deletePost
**编辑 我尝试在 thead 下添加 tr 标签,这会导致额外的错误。这就是我将代码更改为:
```
React.DOM.table
className: 'table table-bordered'
React.DOM.thead null
React.DOM.tr null
React.DOM.th null, 'Description'
React.DOM.th null, 'Actions'
React.DOM.tbody null,
for post in @state.posts
React.createElement Post, key: post.id, post: post,
handleDeletePost: @deletePost
我得到的下一个错误是:警告:validateDOMNesting(...):tr 不能作为表的子项出现。请参见(未知)> 表格 > tr。在您的代码中添加一个以匹配浏览器生成的 DOM 树。
我是 React 新手,不熟悉 coffeescript,所以我想知道它是否与间距有关。测试了不同的间距,但没有帮助。我一起取出了 thead,这导致我的应用程序崩溃,所以..不确定是什么问题
最佳答案
The only direct children allowed for thead
are tr
elements ,不是第 。
<table>
<thead>
<tr>
<th />
</tr>
</thead>
...
</table>
关于javascript - react 错误 <th> 不能作为 <thead> 的子项出现。参见(未知)> thead > th,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43958700/