在gridview中使用onclick事件吗?
错误:试图获取非对象的属性
['class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete} {myButton}',
'buttons' => [
'format' => 'raw',
'myButton' => function ($model) {
return Html::a('<li class="fa fa-folder"></li> info sale', ['#'], [
'class' => 'btn btn-primary btn-xs',
'onclick'=>'saleinfo('.$model->id.')',
]);
}
]
],
答案 0 :(得分:0)
您可以尝试
['class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete} {myButton}',
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
....
}
if ($action === 'update') {
...
}
if ($action === 'myButton') {
$url =\yii\helpers\Url::to(['/your_controller/your_action', 'id' => $model->id]);
return $url;
}
},
'buttons' => [
'myButton' => function($url, $model){
return Html::a('<li class="fa fa-folder"></li> info sale', ['#'], [
'class' => 'btn btn-primary btn-xs',
]);
}
],
],