我认为您可以通过两种方式来实现这一点。首先,将父视图传递给子视图。其次,创建一个处理事件触发的 eventAggregator。
第一:
您可以将 appView 作为选项传递给 previewDataView。
preview = new previewDataView({ // your options, 'parent':this });
在您的 previewDataView 中,您可以像这样绑定到父自定义事件:
this.parent = this.options.parent;
this.parent.bind('eventName', this.onEvent, this);
第二:(刚学会这个技巧)
您可以创建一个 eventAggregator 来帮助您的视图订阅和取消订阅彼此有意义的事件。这是一个很好的答案,在 Stack 上详细解释了这一点:fire an event from one view to another in backbone
在 cmets 中,@Brian Genisio 更进一步将其包含在他的代码中:
Backbone.View.prototype.eventAggregator = _.extend({}, Backbone.Events);
在您的代码开头运行此程序,每个视图都可以访问 eventAggregator,它是您需要跨视图触发和接收的事件的中心枢纽。你可以这样使用它:
// Parent View
this.eventAggregator.trigger('someEvent');
// Child View
this.eventAggregator.bind('someEvent', this.function, this);
这样,您不必在需要相互访问以进行事件触发和侦听的视图之间显式传递引用。这种方法对我来说非常方便。 :-)