2016-01-06 19 views
2

我很想知道是否有一種方法來綁定一些回調在撰寫屬性是Aurelia.js。撰寫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> 

回答

2

的 「奧裏利亞方式」 這樣做將是:

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> 
+0

哇真棒!謝謝 –