2017-05-13 25 views
8

我對工作做出反應 - Rails應用程序,我不斷收到此錯誤在我的控制檯:REACT ERROR <th>不能作爲<thead>的子代出現。見(未知)> THEAD>日

``` 
Warning: validateDOMNesting(...): <th> cannot appear as a child of <thead>. 
See (unknown) > thead > th. 

我不知道這是爲什麼不working..I想要使用header(thead)作爲表格,並且適用於其他人。我會把tbody,但我需要爲表的實際主體。

這裏是我此表代碼:

``` 
    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不能作爲表的子表。參見(未知)> table> tr。添加一個代碼以匹配瀏覽器生成的DOM樹。

我是新來的反應和不熟悉咖啡的腳本,所以我想知道它是否與間距或什麼有關。測試了不同的間距,並沒有幫助。我拿出了所有的一起,這導致我的應用程序打破所以..不知道有什麼問題

+0

它應該是'thead> tr> th' – zerkms

回答

8

th應該下tr不是thead嵌套。

<table> 
 
    <thead> 
 
    <tr> 
 
     <th>name</th> 
 
     <th>age</th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr> 
 
     <td>john</td> 
 
     <td>33</td> 
 
    </tr> 
 
    <tr> 
 
     <td>smith</td> 
 
     <td>22</td> 
 
    </tr> 
 
    <tr> 
 
     <td>jane</td> 
 
     <td>24</td> 
 
    </tr> 
 
    </tbody> 
 
</table>

+0

我已經嘗試在我的代碼下添加tr,但它給了我一個額外的錯誤。 – DianaBG

+0

'''React.DOM.table 的className: '表的表,鑲上' React.DOM.thead空 React.DOM.tr空 React.DOM.th空, '說明' React.DOM.th空, '操作' React.DOM.tbody空, 爲崗位在@ state.posts React.createElement後,鍵:post.id,崗位:崗位, handleDeletePost:@deletePost – DianaBG

+0

我仍然那麼有我原來的誤差以及「tr不能出現在桌子上」和 – DianaBG

1

我有這個錯誤上來,因爲其他地方的錯誤在我的名單。

例如@ Sag1v有<tbody>而不是</tbody>來關閉他的列表的主體,我敢打賭,這是導致錯誤。

相關問題