28.React使用map循環創建對象綁定click無效解決方法
阿新 • • 發佈:2017-08-04
char pan style 鉆石 function blog lec [] 創建對象
var RechargeBtnEle = React.createClass({ getInitialState: function() { return {id:0}; }, handleClick(item,item1){ console.log(item,item1) }, render(){ let btnArr = this.props.data var newArr = [] for(let i=0;i<btnArr.length;i++){var item = btnArr[i] let styleObj = this.state.id==item.id?["recharge","btn","btn-default","btn-sm","selected"].join(‘ ‘):["recharge","btn","btn-default","btn-sm"].join(" ") newArr.push( <div className={styleObj} onClick={this.handleClick.bind(this.item,item)} >{`${item.diamond}鉆石`}</div> ) } return( <div className="charge-btn"> {newArr} </div> ) } })
28.React使用map循環創建對象綁定click無效解決方法