我有一个PhotoCardView
:
var PhotoCardView = Backbone.View.extend({
initialize: function() { this.render(); },
events: { 'click img': 'activateItem' },
activateItem: function(e) {
e.preventDefault();
bus.trigger('switchToFullScreen', {activatorId: this.model.get('id')});
}
// ...
和父母PhotosListView
:
var PhotosListView = Backbone.View.extend({
initialize: function() {
bus.on('switchToFullScreen', function(args) {
this.switchToFullScreen(args);
}, this);
this.render();
},
switchToFullScreen: function(args) {
new ImageGalleryView({
activatorId: args.activatorId,
collection: this.collection
});
},
// ...
列表视图在应用程序路由处理程序之一处理:
sampleRouteHandler: function(param1, param2, param3) {
// ...
photosList.fetch({
success: function() {
var photosListView = new PhotosListView({
collection: photosList,
page: p
});
$('#content').append(photosListView.el);
// ...
假设我添加了代码来“杀死”子视图和父视图,如此处所述Backbone.js - 删除所有子视图
但是我应该从哪里开始呢?我也不知道如何处理事件总线的事情。