2016-10-25 5 views

答えて

0

私はイベントバインディングで補間を使用しようとしていました。代わりに、関数としてVMを参照する方がずっと良かったです。

あなたはビューモデルのプロパティとしてアクションがあったとします。そのプロパティの値を、モデルまたはUIアクションに基づいて正しいメソッドに設定し、メソッドがメソッドとして呼び出されたときに、適切なadd/edit/cancelメソッドが呼び出されます。ビュー・モデル(ES6)内部

:テンプレート内の

setAction(method) { 
    if(method === "edit") { 
    this.action = this.editMethod; 
    } else if(method === "add") { 
    this.action = this.addMethod; 
    } else { 
    this.action = this.cancelMethod; 
    } 
} 

editMethod() { 
    alert("edit"); 
} 

addMethod() { 
    alert("add"); 
} 

cancelMethod() { 
    alert("cancel/default"); 
} 

<button click.delegate="setAction('edit')">Use Edit Method</button> 
<button click.delegate="setAction('add')">Use Add Method</button> 
<button click.delegate="setAction('cancel')">Use Cancel Method</button> 
<button click.delegate="action()">action</button> 
0

ジェレミーDanyowはアウレリア結合のためのgithubの問題フォーラムに答えを提供します。

<button click.delegate="$this[action]()">${action}</button> 
関連する問題