gpt4 book ai didi

javascript - 如何触发 Yii2 确认对话框

转载 作者:可可西里 更新时间:2023-11-01 13:44:50 28 4
gpt4 key购买 nike

我在 GridView 上有一个自定义的 ActionColumn 并尝试使用 data-confirm 调用 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;
},
],

但是当我尝试在没有下拉列表的情况下添加链接时它起作用了

[
'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;
},
],

最佳答案

你可以这样添加一个链接

    <?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',
],
]) ?>

关于javascript - 如何触发 Yii2 确认对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35440274/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com