我有一个要通过 React 输出的对象:
question = {
text: "Is this a good question?",
answers: [
"Yes",
"No",
"I don't know"
]
}
我的react组件(减少)是另一个组件
class QuestionSet extends Component {
render(){
<div className="container">
<h1>{this.props.question.text}</h1>
{this.props.question.answers.forEach(answer => {
console.log("Entered"); //This does ifre
<Answer answer={answer} /> //THIS DOES NOT WORK
})}
}
export default QuestionSet;
正如您从上面的代码段中看到的,我试图通过在 props 中使用数组 Answers 来插入组件 Answers 的数组,它确实会迭代但不会输出到 HTML 中。