考虑一个定义对象列表的视图:
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()
)?
归档时间: |
|
查看次数: |
3976 次 |
最近记录: |