将自定义值连接到按钮并将它们传递给函数
Connecting custom values to button and passing them to function
我有一个模式(使用 bootstrap 4 进行反应)。我想要两个按钮将值传递给绑定函数。我该怎么做?
这是我的代码
这是组件
<Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className}>
<ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
<ModalBody>
<WeatherInfo
nameOfCity={nameOfCity}
weatherDescription={weatherDescription}
windSpeed={windSpeed}
temperature={temperature}
maxTemperature={maxTemperature}
minTemperature={minTemperature}
isChec={isChec}
change={this.toggleCheckboxChange.bind(this)}
/>
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={function(){this.addToMyCityList.bind(this); this.toggle()}}>Add City</Button>{' '}
<Button color="primary" onClick={function(){this.removeFromMyCityList.bind(this); this.toggle()}}>Remove City</Button>{' '}
</ModalFooter>
</Modal>
这些是应该获得价值的函数
addToMyPCityList(e) {
this.props.dispatch(mPkArrayAdd(e.target.nameOfCity.value))
}
removeFromMyCityList(e) {
this.props.dispatch(mPkArrayRemove(e.target.nameOfCity.value))
}
这应该有效
<Button color="primary" onClick={function(e){this.addToMyCityList(e, myParam); this.toggle()}}>Add City</Button>
addToMyCityList(e, myParam) {}
我有一个模式(使用 bootstrap 4 进行反应)。我想要两个按钮将值传递给绑定函数。我该怎么做?
这是我的代码
这是组件
<Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className}>
<ModalHeader toggle={this.toggle}>Modal title</ModalHeader>
<ModalBody>
<WeatherInfo
nameOfCity={nameOfCity}
weatherDescription={weatherDescription}
windSpeed={windSpeed}
temperature={temperature}
maxTemperature={maxTemperature}
minTemperature={minTemperature}
isChec={isChec}
change={this.toggleCheckboxChange.bind(this)}
/>
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={function(){this.addToMyCityList.bind(this); this.toggle()}}>Add City</Button>{' '}
<Button color="primary" onClick={function(){this.removeFromMyCityList.bind(this); this.toggle()}}>Remove City</Button>{' '}
</ModalFooter>
</Modal>
这些是应该获得价值的函数
addToMyPCityList(e) {
this.props.dispatch(mPkArrayAdd(e.target.nameOfCity.value))
}
removeFromMyCityList(e) {
this.props.dispatch(mPkArrayRemove(e.target.nameOfCity.value))
}
这应该有效
<Button color="primary" onClick={function(e){this.addToMyCityList(e, myParam); this.toggle()}}>Add City</Button>
addToMyCityList(e, myParam) {}