我想知道有没有办法在compose属性上绑定一些回调,是Aurelia.js。
我试图做那样的事情
view.html
<a click.delegate="changeTab('first')">Tab 1</a>
<a click.delegate="changeTab('second')">Tab 2</a>
<a click.delegate="changeTab('third')">Tab 3</a>
<compose view-model.bind="tab"></compose>
在每个标签页上,我在attached
活动
first.js
import {inject} from 'aurelia-framework';
@inject(Element)
export class First {
constructor(element) {
this.element = element;
}
attached() {
$(this.element).find('code').each(function () {
Prism.highlightElement($(this)[0]);
});
}
}
问题是
<compose>
是否有与我绑定的类似事件?我的意思是
view.html
<compose view-model.bind="tab" attached.bind="composeAttached()"></compose>
答案 0 :(得分:3)
这样做的“Aurelia方式”将是:
import {inject, customAttribute} from 'aurelia-framework';
@customAttribute('syntax-highlight')
@inject(Element)
export class SyntaxHighlight {
constructor(element) {
this.element = element;
}
attached() {
Prism.highlightElement(this.element);
}
}
<pre><code syntax-highlight>...</code></pre>