Gridview行上的Yii2模式

Gridview行上的Yii2模式,yii2,Yii2,我的模式窗口仅显示在Gridview的第一行(单击第二行或更多行将打开一个没有格式的新页面) 我一直在关注这个 有人能帮我吗?我发现同样的问题还有一个没有答案的话题 我的gridview <?php yii\bootstrap\Modal::begin([ 'id' =>'modal', //'headerOptions' => ['id' => 'modalHeader'], 'header' => 'Tipos de

我的模式窗口仅显示在Gridview的第一行(单击第二行或更多行将打开一个没有格式的新页面)

我一直在关注这个

有人能帮我吗?我发现同样的问题还有一个没有答案的话题

我的gridview

<?php
    yii\bootstrap\Modal::begin([
      'id' =>'modal',
      //'headerOptions' => ['id' => 'modalHeader'],
      'header' => 'Tipos de situação',
    ]);
    yii\bootstrap\Modal::end();
?>

列…

    [
      'attribute' => 'status_id',
      'enableSorting' => true,
      'format' => 'raw',
      'value' => function ($model) {
              // return '<b style="color:#456789">'.$model->status->name.'</b>';
              // },
              return Html::a($model->status->name, ['/analise/status/list'], ['id' => 'popupModal']);      
      },
      'filter' => ArrayHelper::map(Status::find()->orderBy('name')->asArray()->all(), 'id', 'name'),
      'contentOptions'=>['style'=>'width: 10%;text-align:center;vertical-align: middle;'],
      'headerOptions'=>['class'=>'active', 'style'=>'text-align:center;vertical-align: middle;'],
    ],

    <?php
$this->registerJs("$(function() {
   $('#popupModal').click(function(e) {
     e.preventDefault();
     $('#modal').modal('show').find('.modal-body')
     .load($(this).attr('href'));
   });
});");
?>
[
'attribute'=>'status_id',
“enableSorting”=>true,
'格式'=>'原始',
“值”=>函数($model){
//返回“”。$model->status->name。“;
// },
返回Html::a($model->status->name,['/analise/status/list'],['id'=>'popupmodel']);
},
'filter'=>ArrayHelper::map(状态::find()->orderBy('name')->asArray()->all(),'id','name'),
“内容选项”=>[“样式”=>“宽度:10%;文本对齐:中间;垂直对齐:中间;”],
“标题选项”=>[“类”=>“活动”,“样式”=>“文本对齐:居中;垂直对齐:中间;”],
],

你有多个相同id的链接“popupModal”,这是不对的。您可以使用css类而不是id:

在第列中:

'value' => function ($model) {
    return Html::a($model->status->name, ['/analise/status/list'], ['class' => 'popupModal']);
},
在js中:

$this->registerJs("$(function() {
   $('.popupModal').click(function(e) {
     e.preventDefault();
     $('#modal').modal('show')
         .find('.modal-body')
         .load($(this).attr('href'));
   });
});");

你有多个相同id的链接“popupModal”,这是不对的。您可以使用css类而不是id:

在第列中:

'value' => function ($model) {
    return Html::a($model->status->name, ['/analise/status/list'], ['class' => 'popupModal']);
},
在js中:

$this->registerJs("$(function() {
   $('.popupModal').click(function(e) {
     e.preventDefault();
     $('#modal').modal('show')
         .find('.modal-body')
         .load($(this).attr('href'));
   });
});");