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 :(
)

我知道我可以在上下文中传递。但我想知道是否有办法获得实际事件。

4

1 回答 1

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"}}
于 2013-01-22T18:45:50.943 回答