StopPropogation()在ON_DISPATCH事件中不会短路

时间:2016-04-25 21:11:04

标签: php zend-framework2

<?php


namespace Inventionary;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);



        $eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this, 'OnDispatch']);
        $eventManager->attach(MvcEvent::EVENT_RENDER, [$this, 'OnRender']);
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }


    public function onDispatch(MvcEvent $e)
    {
        xdebug_var_dump("Route Dispatch");

        xdebug_var_dump($e->getRouteMatch());
        $e->stopPropagation(true);

        xdebug_var_dump($e->propagationIsStopped());
       //return new \Zend\Http\Response();

    }

    public function onRender(MvcEvent $e)
    {
        xdebug_var_dump("Before Render");
        xdebug_var_dump($e->getRequest()->getMetadata());
        xdebug_var_dump($e->getRouteMatch());

    }
}

我原本以为永远不会看到

  

“渲染之前”

但它正在显示它。

如果我从onDispatch()返回Response对象,它将按预期工作。请详细解释为什么stopPropogation()不会阻止触发onRender()回调。如何在不返回Response对象的情况下使其工作。我有点不清楚它是如何在内部工作的。

1 个答案:

答案 0 :(得分:1)

var myApp = angular.module('myApp', []); function MyCtrl($scope, $timeout) { $scope.$watch('$viewContentLoaded', function() { $timeout(function() { $('.table1 tr').each(function() { $('.table2 tr').height($(this).height()); }); }); }); $scope.table1 = [{ text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis sem ut pharetra sagittis. Nam luctus suscipit augue at suscipit. Maecenas quis justo mauris.' }]; $scope.table2 = [{ text: 'Lorem ipsum dolor sit amet' }]; } 停止对附加到所述事件的侦听器的进一步处理,而不是完全停止所有剩余事件。