仅在Yii2中使用Pjax渲染布局菜单

时间:2016-01-28 04:51:27

标签: jquery yii2 pjax

我试图在yii2中的facebook菜单栏中实现通知。基本上,我打开下拉列表时使用Pjax来检索数据。

function getNotification(){
    //the resason of length 0 instead of 1 because this code is executed first then the notifcation is opened
    if($('#notif-expansion').parent().find('.open').length == 0){
       $("#notification-form").submit();
    }
}

菜单通知位于菜单栏/ layout / main.php中 代码看起来像这样。

    echo Html::beginForm(['../../notification/index'], 'post', ['id' => 'notification-form', 'data-pjax' => '', 'class' => 'form-inline']);

    echo "
        <ul class='navbar-nav navbar-right nav'>
            <!-- id notif-expansion is used in js to check whether the dropdown is opened or closed-->
            <li id='notif-expansion' class='dropdown dropdown-large'>
                <a class='dropdown-toggle' onclick='getNotification()' data-toggle='dropdown'>
                    <span class='glyphicon glyphicon-alert'>
                    </span>
                    <b class='caret'></b>
                </a>
                <ul  class='dropdown-menu dropdown-menu-large row'>
                    <div class='col-md-12'>
                        <label><div style='width:400px' align='center'> Notifications </div></label>
                        <hr>";

                        if(isset($recent_notifications_provider)){
                            echo $this->render('_notifications', ['recent_notifications_provider' => $recent_notifications_provider]);
                        }
                        else{
                            echo Spinner::widget(['preset' => 'medium', 'align' => 'center', 'color' => 'blue']);

                        }

    echo  "        </div>
                </ul>
            </li>
        </ul>
     ";

    echo  Html::endForm();

因此,当单击菜单时,将触发getNotification功能 然后提交表单并执行下面的功能

public function actionIndex(){
    $this->renderAjax('../../layout/main', ['recentnotificationprovider' , $recentnotificationprovider);
}

我只是混淆了渲染的地方,因为我不知道当前页面。

任何人都有解决方案吗? (我对其他解决方案持开放态度)

0 个答案:

没有答案