Javascript Aurelia components元素和jQuery最近函数

Javascript Aurelia components元素和jQuery最近函数,javascript,jquery,binding,aurelia,Javascript,Jquery,Binding,Aurelia,我不明白为什么这样的代码返回空数组。我尝试实现简单的逻辑,当我点击外部控制按钮时,wana关闭弹出窗口 当我在控件内单击时,问题$(elem).closest('custom-popup')总是空数组。我正在做类似的事情 code.js import {inject} from 'aurelia-framework'; @inject(Element) export class CustomPopup { constructor(element) { this.elem

我不明白为什么这样的代码返回空数组。我尝试实现简单的逻辑,当我点击外部控制按钮时,wana关闭弹出窗口

当我在控件内单击时,问题
$(elem).closest('custom-popup')
总是空数组。我正在做类似的事情

code.js

import {inject} from 'aurelia-framework';

@inject(Element)
export class CustomPopup {
    constructor(element) {
        this.element = element
    }

    attached() {
       $(document).on('click', e => this.cancelEvent(e));
    }

    cancelEvent(e){
       elem = e.target;
       if (elem !== this.element && $(elem).closest('custom-popup')[0] !== this.element)
         $(this.element).toggleClass('hide');
    }
}

尝试将
console.log(e.target.outerHTML)
添加到cancel方法中。这可能会让我们对正在发生的事情有所了解。
console.log(e.target.outerHTML)
show me html inside
tag您应该能够在没有jquery的情况下完成这项工作,这就是使用类似于Aurelia的框架的意义所在。我不确定你的html,但是你的组件是否也会显示一个背景覆盖,上面有你的弹出内容?在这种情况下,您应该能够绑定到覆盖上的单击事件(
click.delegete(someFunc)
),然后使用
if.bind
visible.bind
显示/隐藏弹出窗口。如果你分享你的html模板,我可以提供一个更详细的答案