0

我有许多包含参数的链接,这些参数将打开一个填充有 ajax 调用的对话框。

示例链接:

<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,但这些似乎不会干扰任何事情。

当我尝试单击任何此类“附加文件”链接时,对话框打开得很好,一切都按预期工作。我看到了我的gridview,我可以添加和删除文件。但是,当我关闭对话框时,它不会打开此链接或任何其他“附加文件”链接。

重新单击链接后,我在控制台中遇到的错误是:

未捕获的类型错误:modal.dialog 不是函数

我只是在使用gridview时才遇到这种情况,当我注释掉这个小部件代码时,我可以随意随意打开和关闭这些对话框。

任何帮助将不胜感激 :)

4

1 回答 1

1

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

Yii::app()->getClientScript()
    ->scriptMap = array(
    'jquery.js' => false,
    'jquery-ui.min.js' => false
);
于 2017-11-07T11:57:14.980 回答