CJuiDialog 不会重新打开里面的 CGridview

CJuiDialog will not re-open with CGridview inside

我有许多 link 包含参数,这些参数将打开一个对话框,其中填充了 ajax 调用。

样本link:

<a href="javascript:void(0)" id="attach_file_project_454" class="attach_timesheet_file" data-id="454" data-week-start="2017-08-18" data-week-end="2017-08-24">Attach File</a>

这是模式的触发器:

$(".attach_timesheet_file").on("click", function(e) {
    e.preventDefault();
    var url = "<?=Yii::app()->createUrl('admin/timesheetNew/attachTimesheet')?>";
    var id = $(this).data("id");
    var weekStart = $(this).data("week-start");
    var weekEnd = $(this).data("week-end");
    $.ajax({
        type: 'POST',
        url:url,
        data: {
            id: id,
            week_start: weekStart,
            week_end: weekEnd
        },
        success: function(data) {
            var modal = $("#attachFileModal");
            try{
                modal.html(data);
            }
            catch(error)
            {
                console.log(error);
            }
            modal.dialog('open');
            return true;
        }
    })
});

ajax调用的基本动作:

public function actionAttachTimesheet(){
    $projectId = Yii::app()->request->getPost('id', null);
    $reportedWeekStart = Yii::app()->request->getPost('week_start', null);
    $reportedWeekEnd = Yii::app()->request->getPost('week_end', null);

    $this->renderPartial("_attachTimesheet", [
        'projectId' => $projectId,
        'reportedWeekStart' => $reportedWeekStart,
        'reportedWeekEnd' => $reportedWeekEnd,
        'dataProvider' => TimesheetAdditionalFile::additionalFilesDataProvider($projectId, $reportedWeekStart, $reportedWeekEnd)
    ], false, true);
}

最后是对话框中的 CGridView 小部件:

$this->widget('zii.widgets.grid.CGridView', [
    'id' => 'files-grid',
    'dataProvider' => $dataProvider,
    'columns' => [
        [
            'name' => 'filename',
            'header' => 'File Name',
            'value' => 'CHtml::link($data["filename"], Yii::app()->baseUrl . TimesheetNew::FILES_FOLDER . $data["filename"], ["class" => ($data["filetype"] == "pdf")?"fancybox_pdf":"fancybox_picture"])',
            'type'=>'raw',
            'headerHtmlOptions'=>array('style'=>'width: 250px'),
        ],
        [
            'class' => 'CButtonColumn',
            'template' => '{delete}',
            'buttons' => [
                'delete' => [
                    'label' => 'Delete',
                    'imageUrl' => null,
                    'url' => 'Yii::app()->createUrl("admin/timesheetNew/deleteFile", ["id" => $data["id"]])'
                ]
            ],
            'deleteConfirmation'=>'Are you sure you want to delete this file?',
        ]
    ]
]);

我还在模态框内使用了 qq.FileUploader 和 fancybox,但这些似乎不会干扰任何东西。

当我尝试单击任何此类 "attach file" link 时,对话框打开得很好并且一切正常。我看到了我的 gridview,我可以添加和删除文件。但是,当我关闭对话框时,它不会打开此 link 或任何其他 "attach file" links.

我在控制台中遇到的错误是重新单击 link:

Uncaught TypeError: modal.dialog is not a function

我只是在使用gridview的时候遇到过,当我注释掉这个widget代码的时候,我就可以随意打开关闭这些对话框了。

任何帮助将不胜感激:)

解决方案相当简单。通过在视图文件的顶部添加这些行,对话框可以再次无限期地打开和关闭。

Yii::app()->getClientScript()
    ->scriptMap = array(
    'jquery.js' => false,
    'jquery-ui.min.js' => false
);