[英]Aurelia: How to call a function outside custom element?
我有一個名為custom-element的自定義元素,我把它放在模板A中(帶有控制器A)
export class CustomElem {
@bindable onCompleted;
........
}
而updateDescription()是控制器A的一個功能。
export class A {
updateDescription(){
....
}
}
如何使用custom-element調用updateDescription()?
使用call
binding命令提供對自定義元素的函數調用的引用:
<custom-element on-completed.call="updateDescription()"></custom-element>
要使用參數調用updateDescription
方法,可以執行以下操作:
export class CustomElem {
@bindable onCompleted;
...
fooBarBaz() {
var args = {
something: 'A',
somethingElse: 'B',
anotherArg: 'C'
};
this.onCompleted(args);
}
}
<custom-element on-completed.call="updateDescription(something, somethingElse, anotherArg)"></custom-element>
export class A {
updateDescription = () => {
};
}
然后
<custom-element on-completed.bind="updateDescription"></custom-element>
在CustomElem
里面調用this.onCompleted()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.