1
我有一個視圖,一個CollectionView呈現在這個視圖的一個區域內。我如何讓View觀看CollectionView的事件?Backbone/Marionette - 如何聆聽地區兒童視圖上的活動?
const ChildCollectionView = marionette.CollectionView.extend({
// ...
events: {
'click .bar': 'clickBar',
},
clickBar() {
this.trigger('clickBar');
},
});
const ParentView = marionette.View.extend({
// ...
regions: {
foo: '.foo',
},
// ...
onRender() {
const fooRegion = this.getRegion('foo');
fooRegion.on('show', function(view) {
// XXX: this does not work
view.on('childview:clickBar', function() {
console.log('click bar');
});
});
fooRegion.show(new ChildCollectionView({
// ...
}))
},
});