Questions tagged «react-props»


1
在JSX中反应foreach
我有一个要通过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来插入组件Answer的数组,它确实有效,但不会输出到HTML中。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.