如何从此地图方法的功能中访问常量answer
?
如果我将this
传递给地图方法,则会定义this.props.answer
,但answer
仍未定义。
export default class QuestionList extends React.Component {
static propTypes = {
question: ImmutablePropTypes.map,
answer: ImmutablePropTypes.map
};
render() {
const question = this.props.question;
const inputs = question.get('inputs'); // [Input1, Input2, Input3]
const answer = this.props.answer;
const listBody = inputs.map((input, index) => {
console.log(answer); // Uncaught ReferenceError: answer is not defined
});
return (
<div>{listBody}</div>
);
}
}