【发布时间】:2017-01-09 06:53:09
【问题描述】:
我在 GridView 中创建了 onClick 操作,它会将我重定向到控制器中的操作。
Index.php 中的代码:
},
'rowOptions' => function ($model, $key, $index, $grid) {
return ['id' => $model['id'], 'onclick' => 'var myid=this.id; var enteredValue = prompt("Please enter a number");
window.location.href = "index.php?r=patientservices%2Fpassing" + "&id=myid, " + enteredValue; '];
},
在我的控制器代码中:
public function actionPassing($id,$price)
{
$ser= $this->findModel($id);
$model = new Receipts();
$countclinic=Receipts::find()
->where(['patient_services_id'=>$id])
->count();
if ($countclinic== 0) {
$model->patient_id=$ser->patient_id;
$model->price=$price; // the price that i need to pass
$model->doctor_id=$ser->doctor_id;
$model->patient_services_id=$ser->id;
$model->reg_date=DATE('y-m-d h:m:s');
$model->description='دفعة تحت الحساب';
$model->userin = \Yii::$app->user->identity->id ;
$model->save();
$models = $this->findModel($id);
$models->state=2;
$models->save();
JS 代码:
$this->registerJs("
$('.custom_button').on('click', function() {
alert(id);
var enteredValue = prompt('Please enter a number');
if (enteredValue != null) {
window.location.href = 'index.php?r=patientservices%2Fpassing' + '&id=, ' + enteredValue;
}
});
");
我需要的是:
当用户单击 GridView 中的行时,会为用户显示提示文本,并且插入在提示文本中的数字与 ID 一起传递给控制器以在那里使用它,但 js 代码将 id 作为字符而不是数字传递
$model->price=$ser->price;
【问题讨论】:
标签: javascript gridview yii2 yii2-advanced-app