网格视图更新按钮上的Yii2模态对话框未加载更新表单

时间:2016-03-13 07:17:32

标签: forms gridview popup modal-dialog yii2

参考How to implement Yii2 Modal Dialog on Gridview view and update button?。我在下面编写了我的代码,但它会弹出一个没有更新表单的窗口。谁能让我知道正确的代码? (我使用Kartik Gridview)

这是列的代码:

 ['class' => '\kartik\grid\ActionColumn',
         'template'=>'{update}{delete}{view}',//{view}'//{view}{delete}', 
           'headerOptions' => ['width' => '20%', 'class' => 'activity-  update-link',],        
           'contentOptions' => ['class' => 'padding-left-5px'],
            'buttons' => [
               'update' => function ($url, $model, $key) {
                   return Html::a('<span class="glyphicon glyphicon-pencil"></span>','/projects/update?id='.$key.'', [
                       'class' => 'activity-update-link',
                       'title' => Yii::t('yii', 'Project Update'),
                       'data-toggle' => 'modal',
                       'data-target' => '#activity-modal',
                       'data-id' => $key,
                       'data-pjax' => '0',
                                ]);
                            },
                        ],
        ],

这是JS代码:

<?php $this->registerJs(
'
function init_click_handlers(){
$(".activity-update-link").click(function(e) {
        var fID = $(this).closest("tr").data("key");
        $.get(
            "update",
            {
                id: fID
            },
            function (data)
            {
                $("#activity-modal").find(".modal-body").html(data);
                $(".modal-body").html(data);
                $("#activity-modal").modal("show");
            }
        );
    });
}
init_click_handlers(); //first run
$("#project_pjax_id").on("pjax:success", function() {
init_click_handlers(); //reactivate links in grid after pjax update 
});
');
?>
<?php 
Modal::begin([
'id' => 'activity-modal',
'header' => '<h4 class="modal-title">Update Project Testing</h4>',
'size'=>'modal-lg',
'footer' => '<a href="#" class="btn btn-primary" data-   
dismiss="modal">Close</a>',
]); ?>
<div class='well'></div>
<?php Modal::end(); ?>

1 个答案:

答案 0 :(得分:0)

感谢所有人观看我的问题。我通过使用类而不是ID将modal添加到assets文件夹的main.js文件中解决了我的问题。