问题:
I'm trying to do something like the following in React JSX
(where ObjectRow is a separate component): 我正在React JSX
尝试执行以下操作(其中ObjectRow是一个单独的组件):
<tbody>
for (var i=0; i < numrows; i++) {
<ObjectRow/>
}
</tbody>
I realize and understand why this isn't valid JSX
, since JSX
maps to function calls. 我意识到并理解为什么这不是有效的JSX
,因为JSX
映射到函数调用。 However, coming from template land and being new to JSX
, I am unsure how I would achieve the above (adding a component multiple times). 但是,由于来自模板领域并且是JSX
新手,所以我不确定如何实现上述目标(多次添加组件)。
解决方案:
参考一: https://stackoom.com/question/1XzLW/在React-JSX内部循环参考二: https://oldbug.net/q/1XzLW/Loop-inside-React-JSX
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4311428