Taro Pit daily

 The exact parameters can only pass component events referenced in the class scope (this.handleXX || this.props.handleXX), or use a bind.

  Click the following components event

//   Component 
< AtListItem
  key={i}
  isSwitch 
  switchIsCheck={ true } 
  onSwitchChange={ (e) => this.handleSwitchChange(e, i) }
 />

 // Method 
handleSwitchChange = (E, I) => {
  console.log ( 'and:' , s)
  console.log('i :', i)
}

  In the end H5 normal operation, an exception is thrown in the small end of the program:

// Error: component mass participation event only exact quote (this.handleXX || this.props.handleXX) in the class scope, or bind.

  I wrote react students know such an approach more common in the daily, beginning this exception is not my Best Solution

  The final solution is as follows:

  

//   Component 
< AtListItem
  key={i}
  isSwitch 
  switchIsCheck={ true } 
  onSwitchChange={ this.handleSwitchChange.bind(this, i) }
 />

 // Method 
handleSwitchChange = (I, E) => {
  console.log('i :', i)
  (the console.log : 'E' , E)
   // parameter order is different here 
     // The first parameter passed to the assembly method of the index value 
  // second parameter is this, this parameter can bind in You do not need to pass 
}

  The wording of the H5 has little to reach a unified program ended input, this pit too ~

Guess you like

Origin www.cnblogs.com/vant850/p/10926743.html