【发布时间】:2018-05-16 21:56:58
【问题描述】:
我有一个我想通过 React 输出的对象:
question = {
text: "Is this a good question?",
answers: [
"Yes",
"No",
"I don't know"
]
}
而我的反应组件(削减),是另一个组件
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。
【问题讨论】:
标签: reactjs react-props