我有很多包含参数的链接,这些参数会打开一个用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,但这些似乎并没有干扰任何事情。
当我尝试点击任何此类&#34;附加文件&#34;链接,对话框打开就好了,一切都按预期工作。我看到了我的gridview,我可以添加和删除文件。但是,当我关闭对话框时,它不会打开此链接或任何其他&#34;附加文件&#34;链接。
重新点击链接后,我在控制台中出现的错误是:
未捕获的TypeError:modal.dialog不是函数
我只是在使用gridview时遇到这种情况,当我注释掉这个小部件代码时,我可以随意打开和关闭这些对话框。
非常感谢任何帮助:)
答案 0 :(得分:1)
解决方案相当容易。通过在视图文件的顶部添加这些行,可以再次无限期地打开和关闭对话框。
Yii::app()->getClientScript()
->scriptMap = array(
'jquery.js' => false,
'jquery-ui.min.js' => false
);