如何将事件传递给父视图,传递触发事件的子视图?

Pan*_*agi 7 ember.js

考虑一个定义对象列表的视图:

App.ListView = Ember.View({
  items: 'App.FooController.content'

  itemClicked: function(item){

  }
)};
Run Code Online (Sandbox Code Playgroud)

使用模板:

<ul>
{{#each items}}
    {{#view App.ItemView itemBinding="this" tagName="li"}}
      <!-- ... -->
    {{/view}}
{{/each}}
</ul>
Run Code Online (Sandbox Code Playgroud)

和ItemView:

App.ItemView = Ember.View.extend({

  click: function(event){

    var item = this.get('item');

    // I want to call function itemClicked(item) of parentView
    // so that it handles the click event
  }
})
Run Code Online (Sandbox Code Playgroud)

所以基本上我的问题是如何将事件传递给父视图,尤其是在子视图不知道父视图的情况下?据我所知,你可以得到一个属性foo一个parentView与任一this.getPath('parentView').get('foo')this.getPath('contentView').get('foo').但是一个函数呢(在这种情况下itemclicked())?

Tom*_*ore 7

this.get('parentView').itemClicked(this.get('item')); 应该做的伎俩.