我使用的是ReactJs的ConfirmAlert插件,它提供了当用户单击确认对话框上的是或否时应该发生的事情的灵活性。但是当我单击Yes时,我希望调用一个函数来执行一些工作。但问题是,当我单击“是”时,函数不会被调用。我不知道我做错了什么。
我可以使用window.confirm()方法实现这一点。但是我想使用ReactJs提供的ConfirmAlert插件。
handleClick = (value) => {
value.map(item => {
if (item.props.status) {
confirmAlert({
title: "message",
message: "Are you sure?",
buttons: [
{
label: 'Yes',
onclick: () =>
(this.formCollection(item.props.name, item.props.id) // Does not Fire.
},
{
label: 'No',
onClick: () => window.alert("Subscription Aborted!!") // Works fine.
}
]
})
}
})
}
formCollection = (name, id) => {
// doing desired work here.
}
<input type = "button" onclick={this.handleClick(alerts)} />
我希望formCollection方法在用户单击确认对话框上的“是”时获得触发器。
发布于 2019-05-30 06:02:11
事件名称应为camelCase
buttons: [{
label: 'Yes',
onClick: () =>
this.formCollection(item.props.name, item.props.id)
},
{
label: 'No',
onClick: () => window.alert("Subscription Aborted!!")
}
]
https://stackoverflow.com/questions/56372183
复制