【问题标题】:Yii menu linkOptions not working with ajaxYii 菜单链接选项不适用于 ajax
【发布时间】:2014-12-11 10:44:40
【问题描述】:

我正在尝试在 CJuiDialog 中显示 CGridView,但遇到了一些问题。 在我看来,我创建了一个菜单项如下:

$this->menu = array(
    array('label' => Yii::t('app', 'Afficher les participants ayant fourni cette information'), 
        'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
        'linkOptions' => array(
            //'onclick' => "{viewP(); $('#dialogViewP').dialog('open'); return false}",
            'ajax' => array(
                'type' => 'POST',
                'url' =>"js:$(this).attr('href')", //array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
                'update' => '#divForForm2',
            ),
        ),
);

然后我创建了对话框:

<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'dialogViewP',
        'options' => array(
            'title' => 'Liste des participants ayant fourni cette information',
            'autoOpen' => false,
            'modal' => true,
            'width' => 500,
            'height' => 300,
        ),
     ));
    ?>
    <div id="divForForm2"></div>
    <?php $this->endWidget('dialogViewP'); ?>

我的控制器看起来像这样:

public function actionShowParticipantInfo($id){
        $rows = Participant::findParticipantInfo($id);

            $result = array();
            foreach ($rows AS $key => $val){
                $result[] = array('id' => $key +1, 'value' => $val['NomComplet']);
            }
            $arrayDataProvider = new CArrayDataProvider($result, array(
                'id' => 'id',
                'pagination' => array(
                    'pageSize' => 10,
                ),
            ));
        if(Yii::app()->request->isAjaxRequest){

            $this->renderPartial('_showparticipant', array(
                    'arrayDataProvider' => $arrayDataProvider,
                    ), false, true);
            echo CHtml::script('$("#dialogViewP").dialog("open")');
            Yii::app()->end();
        }
    }

但是,但是单击菜单项,会显示任何对话框。我不知道为什么。有人可以帮我吗?

【问题讨论】:

    标签: php jquery ajax yii


    【解决方案1】:

    我认为菜单项中不应同时存在“url”和“linkOption”属性。任意一个。 通过网络开发工具,您需要检查单击菜单项时是否有 ajax XHR

    如果你想实现一个 ajax 手册,我推荐你this extention

    即使您发起 ajax 请求,响应也无法激活隐藏对话框,因为成功后您只能更新某些 div #divForForm2 但对话框窗口仍然关闭:'autoOpen' =&gt; false。我建议在 ajax 成功后合并打开对话框。

     'ajax' => array(
           'type' => 'POST',
           'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
           'success' =>'js:{function(data){$("#divForForm2").html(data); $("#dialogViewP").dialog("open");}' 
            ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      • 2017-06-22
      • 2015-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      相关资源
      最近更新 更多