考虑一个视图定义对象的列表:与模板如何将事件传递给父视图,传递触发事件的子视图?
App.ListView = Ember.View({
items: 'App.FooController.content'
itemClicked: function(item){
}
)};
:
<ul>
{{#each items}}
{{#view App.ItemView itemBinding="this" tagName="li"}}
<!-- ... -->
{{/view}}
{{/each}}
</ul>
和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
}
})
所以基本上我的问题是如何传递事件到父视图,特别是在父视图未被子视图所知的情况下?我知道您可以通过this.getPath('parentView').get('foo')
或this.getPath('contentView').get('foo')
获得父视图的属性foo
。但是一个函数怎么样(在这种情况下,itemclicked()
)?
我以为我测试,并没有奏效。我会让一个jsFiddle来测试它。我很确定'this.get('contentView')。itemClicked(this.get('item'));'(用于将事件传递给父母)不起作用。 – 2012-02-21 21:32:48
@Zack它似乎在这里工作:http://jsfiddle.net/tomwhatmore/FGyrV/1/除非我误解了这个问题。可能是因为你使用'getPath()'而不是'get()'? – 2012-02-21 22:31:34
Yeap,我正在使用getPath :) – 2012-02-22 06:09:01