ReactJS:为什么我不能访问.map方法之外的变量?

时间:2016-12-06 16:58:13

标签: reactjs ecmascript-6 immutable.js

如何从此地图方法的功能中访问常量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>
   );
  }
}

0 个答案:

没有答案