使用来自外部的参数访问 React 的函数 JavaScript
Access react's function with parameters from external JavaScript
是否可以在 UIKIT.notification 的消息参数中添加 onclick 事件?
像这样:
notif__undoDelete = (param) => {
setTimeout(function(param) {
UIkit.notification(
`<div class="uk-flex uk-flex-middle uk-margin-medium-right">
<span>Exercise Deleted.</span><a onclick="{here}" class="uk-button uk-button-primary uk-button-small uk-margin-auto-left">Undo</a>
</div>`,
{ timeout: 6000, pos: "bottom-left" }
)
}, 800, param)
}
我用这个答案来解决我的问题
我先在componentDidMount方法中添加了:
componentDidMount () {
var me = this
window.undoDelete = () => {
var external_me = this
let param = JSON.parse(external_me.event.target.getAttribute("data-param"))
me.undoDelete(param)
}
}
我在某个地方有一个 undoDelete()
方法,当我调用我的 UIkit.notification 时,它会是这样的,我的反应的 undoDelete()
方法将被调用。我还添加了数据参数来传递参数。
UIkit.notification(
`<div className="uk-flex uk-flex-middle uk-margin-medium-right">
<span>Item Deleted.</span>
<a onclick="window.undoDeleteExternal()" data-param='`+ JSON.stringify(param) +`' className="uk-button uk-button-primary uk-button-small uk-margin-auto-left">Undo</a>
</div>`,
{ timeout: 6000, pos: 'bottom-left' }
)
是否可以在 UIKIT.notification 的消息参数中添加 onclick 事件?
像这样:
notif__undoDelete = (param) => {
setTimeout(function(param) {
UIkit.notification(
`<div class="uk-flex uk-flex-middle uk-margin-medium-right">
<span>Exercise Deleted.</span><a onclick="{here}" class="uk-button uk-button-primary uk-button-small uk-margin-auto-left">Undo</a>
</div>`,
{ timeout: 6000, pos: "bottom-left" }
)
}, 800, param)
}
我用这个答案来解决我的问题
我先在componentDidMount方法中添加了:
componentDidMount () {
var me = this
window.undoDelete = () => {
var external_me = this
let param = JSON.parse(external_me.event.target.getAttribute("data-param"))
me.undoDelete(param)
}
}
我在某个地方有一个 undoDelete()
方法,当我调用我的 UIkit.notification 时,它会是这样的,我的反应的 undoDelete()
方法将被调用。我还添加了数据参数来传递参数。
UIkit.notification(
`<div className="uk-flex uk-flex-middle uk-margin-medium-right">
<span>Item Deleted.</span>
<a onclick="window.undoDeleteExternal()" data-param='`+ JSON.stringify(param) +`' className="uk-button uk-button-primary uk-button-small uk-margin-auto-left">Undo</a>
</div>`,
{ timeout: 6000, pos: 'bottom-left' }
)