如何触发Yii2确认对话框

Jos*_*osE 5 javascript php jquery yii2

我有一个自定义ActionColumnGridView,并试图调用yii.confirm使用功能的数据证实了删除操作而不是所示的对话框.

[
'format'=>'html',
'content'=>function($data) {
    $btn = ButtonDropdown::widget([
    'label' => 'Action',
    'options' => ['class'=>'btn btn-sm btn-primary dropdown-toggle', 'type'=>'button'],
    'dropdown' => [
        'options' => ['class'=>'dropdown-menu action', 'role'=>'menu'],
        'items' => [
            '<li><a href="'.Url::to(['details','id'=>$data->id]) .'"><i class="fa fa-pencil"></i> Details</a></li>',
            '<li><a href="'. Url::to(['edit', 'id' => $data->id]) .'"><i class="fa fa-eye"></i> Edit</a></li>',
            '<li role="presentation" class="divider"></li>',
            '<li><a data-method="post" data-confirm="Are you sure ?" href="'.Url::to(['delete', 'id' => $data->id]).'"><i class="fa fa-trash"></i> Delete</a></li>',                                                
        ],
    ],
]);
return $btn;
},
],
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试添加链接时没有下拉列表它的工作原理

[
'format'=>'html',//raw, html
    'content'=>function($data) {
        $btn ='<a data-method="post" data-confirm="Are you sure ?" href="'.Url::to(['delete', 'id' => $data->id]).'"><i class="fa   fa-trash"></i> Delete</a>';                                                
        return $btn;
    },
],
Run Code Online (Sandbox Code Playgroud)

cra*_*ter 8

您可以添加这样的链接

    <?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], [
        'class' => 'btn btn-danger',
        'data' => [
            'confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'),
            'method' => 'post',
        ],
    ]) ?>
Run Code Online (Sandbox Code Playgroud)


sca*_*dge 2

我应该使用 linkOtions 表单 Items

     [
    'format'=>'html',
    'content'=>function($data) {
        $btn = ButtonDropdown::widget([
        'label' => 'Action',
        'options' => ['class'=>'btn btn-sm btn-primary dropdown-toggle', 'type'=>'button'],
        'dropdown' => [
            'options' => ['class'=>'dropdown-menu action', 'role'=>'menu'],
            'items' => [
              ['label' => 'Details', 'url' =>  ['details','id'=>$data->id], 
                      'linkOptions' => ['class'=>'fa fa-pencil'],],
              ['label' => 'Edit', 'url' =>  ['edit','id'=>$data->id], 
                      'linkOptions' => ['class'=>'fa fa-eye'],],
              ['label' => '<span role="presentation" class="divider"></span>'],
              ['label' => 'Delete', 'url' =>  ['delete','id'=>$data->id], 
                      'linkOptions' => ['class'=>'fa fa-trash' , 'data' => [
                    'confirm' => 'Are you sure ?',
                    'method' => 'post',
                ]],],                 
            ],
        ],
    ]);
    return $btn;
  },
  ],
Run Code Online (Sandbox Code Playgroud)