[英]How can I return multiple lines JSX in another return statement in React?
[英]Return multiple <tr> lines in React
我希望能夠返回2 <tr>
行,這可以通過包裝在<tbody>
中來實現,如下所示:
var Item = React.createClass({
render: function() {
return (
<tbody>
<tr>/*...*/</tr>
<tr>/*...*/</tr>
</tbody>
);
}
});
但是,我從React收到警告: <tbody>不能作為<tbody>的孩子出現
有沒有其他方法可以做到更友好的DOM?
這對React來說是一個煩人的限制。 <table>
可以包含多個<tbody>
- 將<Item>
作為<table>
的附加<tbody>
呈現給你嗎?
您似乎遇到了最大的JSX根節點問題。 返回中只能有1個根節點,但它可以包含任意數量的子節點。 試試這個:
var Item = React.createClass({
render: function() {
return (
<table> /* <- This is the root node. */
<thead> /* <- Multiple nodes start at this level. */
<tr>/*...*/</tr>
<tr>/*...*/</tr>
</thead>
<tbody>
<tr>/*...*/</tr>
<tr>/*...*/</tr>
<tr>/*...*/</tr>
<tr>/*...*/</tr>
<tr>/*...*/</tr>
</tbody>
<tfoot>
<tr>/*...*/</tr>
<tr>/*...*/</tr>
</tfoot>
</table>
);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.