1

如果在子视图上触发事件,它是否不仅在子视图中处理,也在父视图中处理?

这是一个 Ember View 测试:

test("event manager should be able to re-dispatch events to view", function() {

  var receivedEvent=0;
  view = Ember.ContainerView.createWithMixins({
    elementId: 'containerView',

    eventManager: Ember.Object.create({
      mouseDown: function(evt, view) {
        // Re-dispatch event when you get it.
        //
        // The second parameter tells the dispatcher
        // that this event has been handled. This
        // API will clearly need to be reworked since
        // multiple eventManagers in a single view
        // hierarchy would break, but it shows that
        // re-dispatching works
        view.$().trigger('mousedown',this);
      }
    }),

    childViews: ['child'],

    child: Ember.View.extend({
      elementId: 'nestedView',

      mouseDown: function(evt) {
        receivedEvent++;
      }
    }),

    mouseDown: function(evt) {
      receivedEvent++;
    }
  });

  Ember.run(function() { view.append(); });

  Ember.$('#nestedView').trigger('mousedown');
  equal(receivedEvent, 2, "event should go to manager and not view");
});

我的问题是:为什么receivedEvent是 2,而不是 1?事件处理的顺序是什么?子视图不应该停止事件传播吗?

4

0 回答 0