我将为返回状态的显示数组值创建循环。现在,我按{text.nameSub [0] .nameSub [0] [0] .nameSub},{text.nameSub [0] .nameSub [0] [1] .nameSub}显示,但我不知道create for循环而是这段代码。请帮助我,非常感谢您的建议。
import React,{Component} from 'react'
import '../App.css'
class addEntity extends Component {
constructor(props){
super(props);
this.state ={
index: 1,
entity: []
}
}
render() {
return(
<div>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Entity Type</th>
<th scope="col">Sub-type</th>
<th scope="col">Actions</th>
</tr>
</thead>
{this.state.entity.map((text,index) =>{
return(
<tr key={text.nameEn}>
<th>{index+1}</th>
<td scope="col">{text.nameEn}</td>
<td scope="col">
{text.nameSub[0].nameSub[0][0].nameSub},
{text.nameSub[0].nameSub[0][1].nameSub}
{/* I will create loop for display it here like this {text.nameSub[0].nameSub[0][i].nameSub} */}
</td>
</tr>
)
})}
</table>
</div>
)
}
}
export default addEntity;
答案 0 :(得分:0)
您可以这样迭代
{this.state.entity.map((text,index) =>{
return(
<tr key={text.nameEn}>
<th>{index+1}</th> //this might be `td` and not `th`
<td scope="col">{text.nameEn}</td>
<td scope="col">
{text.nameSub[index].map((name,ind) => {
return <span>{name[ind].nameSub}</span>
})}
</td>
</tr>
)
})}