2016-11-14 45 views
0

我那里有删除按钮自定义操作柱:Yii2定制删除ActionColumn警报两次

[ 
    'class' => 'yii\grid\ActionColumn', 
    'template' => '{delete}', 
    'buttons' => [ 
     'delete' => function($url, $data){ 
      return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['orders-lines/delete', 'id' => $data->id], [ 
       'data' => [ 
        'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 
        'method' => 'post', 
       ], 
      ]); 
     } 
    ] 
], 

,每当我单击回收站图标,然后接受警告框,同样的警告框再次被触发,从而我必须接受两次警报框。

我能错过什么?

感谢

+2

有你有pjax呢?如果是这样,你可以检查,如果你添加''pjax'=>'0',''数据'数组是否会发生同样的情况? – Bizley

+0

感谢您的回答。我不使用pjax,并通过设置pjax = 0 – farrusete

回答

-1

试一下这个

['class' => 'yii\grid\ActionColumn', 
'template' => '{delete}', 
            'buttons' => [ 
             'delete' => function ($url, $data) { 
              return Html::a('<span class="glyphicon glyphicon-trash" title="Delete"></span>', ['orders-lines/delete', 'id' => $data->id], ["data-pjax" => 0, 'onClick' => 'return confirm("Are you sure you want to delete this item?") ']); 
             }, 
              ], 
             ], 
+0

来获得相同的行为。两次添加相同的答案有什么意义,这里有什么不同。它已经通过** Bizley **回答 –

+0

将其设置为onClick事件作品,但是...这是由于yii中的'confirm'方法的问题吗?我需要将id值作为POST请求发送 – farrusete