react jsx 循环_如何在React JSX内部循环

react jsx 循环

If you have a set of elements you need to loop upon to generate a JSX partial, you can create a loop, and then add JSX to an array:

如果有一组元素需要循环以生成JSX部分,则可以创建一个循环,然后将JSX添加到数组中:

const elements = [] //..some arrayconst items = []for ( const [ index , value ] of elements . entries ()) {items . push ( < Element key = { index } /> )
}

Now when rendering the JSX you can embed the items array by wrapping it in curly braces:

现在,当渲染JSX时,您可以通过将其包装在花括号中来嵌入items数组:

render () {const elements = [ 'one' , 'two' , 'three' ];const items = []for ( const [ index , value ] of elements . entries ()) {items . push ( < li key = { index } > {


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部