render(){ if(this.state.loading){ return; }else{ let [header={},bodyHtml='']=[this.state.articleDetail.header]; bodyHtml=this.state.articleDetail.body.content.map(function (item1,index1) { bodyHtml+= {item1.firstTitle}
; item1.firstTitleDes.map(function (item2,index2) { bodyHtml+={item2.secondTitle}
; item2.secondTitleDes.map(function (item3,index3) { bodyHtml+={item3.describle}
; bodyHtml+=; }); }); return (bodyHtml); }); return ({item3.code}
); } }
{header.title}
发表于 {header.date} | in {header.type}
{bodyHtml}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
感觉要么就是你把处理数据的这部分代码放到别的地方去做,要么就是重构逻辑,减少循环嵌套。
用 react 话,不是可以更好的组建化?
你可以将每个循环中的结构单独提为一个组件:Item1,Item2,Item3
当前组件中 map <Item1>
<Item1> 中 map <Item2>
<Item2> 中 map <Item3>。
render(){
冲这个嵌套的程度,我觉得你应该改变结构了,你现在走的路会让你更痛苦。