循环过相似的组件反应为macthing状态?

时间:2018-06-01 09:28:50

标签: javascript reactjs reactive-programming web-deployment jsx

我有一个包含16张牌的牌组。每个牌都有一个名为isOpened的状态,用于检查牌是否被打开。一旦打开两张类似的卡片,我就想将它们锁定在打开的位置。如何循环打开卡组件并检查匹配状态?

constructor(props){
    super(props);
  this.state = {
      isOpened: true,
      currentState: this.props.img, 
      prevState: "doubt.png"
  }
  this.showHideCard = this.showHideCard.bind(this);
  // this.showCard = this.showCard.bind(this);
  // this.setFlagIsOpened = this.setFlagIsOpened.bind(this);
  setTimeout(() => {this.showHideCard();}, 2000);
}
showHideCard(){
  if(this.state.isOpened === false) {
      this.setState({isOpened: true});
      console.log("true");
  } else {
        this.setState({isOpened: false});
        console.log("false");
    }
    this.setState({currentState: this.state.prevState , prevState: this.state.currentState});
}

0 个答案:

没有答案