Backbone.js 主干触发器事件在两种情况下失去上下文

Backbone.js 主干触发器事件在两种情况下失去上下文,backbone.js,backbone-events,Backbone.js,Backbone Events,我们有一个父视图和多个子视图,一种是主视图,另一种是次视图。我们正在同时转换父视图和子视图,为此,我们在父视图中通过dispatch.trigger('transition.event',this)触发一个'transition.event',并在子视图上通过 initialize: function(options) { if(options) { ... we place everything from options.* onto this.* // we can ve

我们有一个父视图和多个子视图,一种是
主视图
,另一种是
次视图
。我们正在同时转换父视图和子视图,为此,我们在父视图中通过
dispatch.trigger('transition.event',this)
触发一个
'transition.event'
,并在子视图上通过

initialize: function(options) {
  if(options) {
    ... we place everything from options.* onto this.*
    // we can verify that the parameters exist coming in from options
    // This is listener A
    dispatch.on('transition.event', this.transition, this);
  }
  ...
  // This is listener B
  dispatch.on('transition.event', this.transition, this);
  this.render();
}
选项案例适用于将类型设置为辅助时

如果删除侦听器A,事件将不起作用,因为上下文丢失。
如果我们删除侦听器B,则事件确实有效,并且上下文当然不会丢失。
如果我们将侦听器A更改为
dispatch.on('secondarytransion.event,this.transition,this)并让侦听器B保持原样,它就工作了

为什么在将条件侦听器设置为主干触发器时会丢失上下文和一些参数

更完整的代码:

父视图:

makeChildViews: function(options){
  this.measurePassingToChildViewParameters = {...};
  // for each child 
  _.all(this.parentMeasureModel.get('beats').models, function(beat, index) {
    // create a Childview
      ...
        this.lineStatesUnrolling = [...];
        this.lineStatesRollup = [...];

    this.measurePassingToChildViewParameters.lineStatesUnrolling = this.lineStatesUnrolling;
    this.measurePassingToChildViewParameters.lineStatesRollup = this.lineStatesRollup;
    // we can verify that the parameters exist when we create the Child view
    new ChildView(this.measurePassingToChildViewParameters);
  }, this);
},
子视图:

transition: function() {
  // even though the parameters came in from the (options) in the init
  // they disappear when we have both listeners set
  console.warn(this);  //here this.lineStatesUnrolling is undefined
  for(i=0; i<this.transitionNumberOfPoints; i++){
      var x = this.transitionNumberOfPoints-i;
      this.BEAT.data([this.lineStatesUnrolling[i]])
          .transition()
          .delay(this.transitionDuration*i)
          .duration(this.transitionDuration)
          .ease('linear')
          .attr('d', this.pathFunction)
  }
},
transition:function(){
//即使参数来自init中的(选项)
//当我们设置了两个侦听器时,它们就会消失
console.warn(this);//此处this.lineStatesUnrolling未定义

对于(i=0;iis)您的调度充当自定义事件总线?@beNerd是的,我继承了这个想法。
dispatch
处理多个视图之间的事件不确定BB中是否有传统的处理方法。。。