2013-01-22 28 views
0
# in the handlebars template  
{{action "do_something" target="view"}} 

# in the view 
APP.view = Ember.View.extend(
    do_something: (evt) -> 
    console.log evt #this used to contain a javascript event object, it was useful at times :(
) 

我知道我可以傳入上下文。但我想知道是否有辦法得到實際的事件。EmberJS前2用於傳遞JS事件對象的動作

回答

1

如果你想要一個事件對象,你需要創建一個自定義的View。下面是一些我在我的應用程序中使用的例子:

App.ProductsGridSortButtonView = Ember.View.extend({ 
    tagName: 'a', 
    classNames: ['productsSortButton'], 
    attributeBindings: ['data-sort','data-sort-type'], 
    click: function(e){ 
    this.get('parentView').sortProducts(e); 
    } 
}); 

,並在模板:

{{#view App.ProductsGridSortButtonView data-sort="price" data-sort-type="number"}} 
+0

我想這會工作....但讓說實話,這是一個可怕的解決方案。我開始質疑Ember與pre4一起採取的方向。設置路由器的新方式很棒,但其他許多事情都被打破了。 – InternalFX

+0

我可以看到你的觀點..它可能需要一段時間才能從pre1移動到最新版本......雖然這是一個核心概念,並且會使代碼更好,但是'view'是你處理用戶交互/ event_的地方指南正在更新,我認爲[見這裏](http://emberjs.com/guides/getting-started/core-concepts/#toc_views) – colymba