EmberJS pre 2用于传递JS事件对象以进行操作

时间:2013-01-22 17:38:24

标签: coffeescript ember.js

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

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

1 个答案:

答案 0 :(得分:1)

如果您需要事件对象,则需要创建自定义View。以下是我在App中使用的示例:

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"}}