gpt4 book ai didi

javascript - 有条件地绑定(bind) Aurelia 中的事件

转载 作者:行者123 更新时间:2023-11-29 11:01:46 24 4
gpt4 key购买 nike

是否可以使用 .trigger() 有条件地绑定(bind)事件或 .delegate()在 html View 中?

这是常规方式:

<div mousedown.delegate="handleMouseDown($event)"></div>

我在想这样的事情:

<div mousedown.delegate="isDraggable ? handleMouseDown($event) : null"></div>

理想情况下如果isDraggable === false没有注册处理程序。

目前我只是在 View 模型中进行这项检查 attached()函数 .addEventListener()有没有更好的办法?

最佳答案

正如@thebluefox 在问题评论中指出的

<div mousedown.delegate="isDraggable ? handleMouseDown($event) : null"></div>

确实有效,但是在添加绑定(bind)行为时存在一些问题。

下面的例子在评估三元时会失败

<div mousedown.delegate="isDraggable ? handleMouseDown($event) & throttle:500 : null"></div>

<div mousedown.delegate="isDraggable ? (handleMouseDown($event) & throttle:500) : null"></div>

作为解决方法,您可以反转测试,以便绑定(bind)在最后,例如

<div mousemove.delegate="!isDraggable ? null : handleMouseMove($event) & throttle:500 "></div>

关于javascript - 有条件地绑定(bind) Aurelia 中的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45815740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com