我的Yii2应用程序中有一个可编辑的GridView,并使用kartik EditableColumn。当只有一个可编辑的列时,一切正常,但是当我尝试添加另一个可编辑的列时,它保存了价格列的已编辑值,并将 expire_days 列的值设置为零。相反的方法也一样(如果更新 expire_days ,它将保存该值,但将 Price 值设置为零)。
视图:
'columns' => [
[
'class'=>'kartik\grid\EditableColumn',
'attribute' => 'price',
'editableOptions'=>[
'header'=>' ',
'inputType'=>\kartik\editable\Editable::INPUT_SPIN,
'options'=>['pluginOptions'=>['min'=>0, 'max'=>5000000]]
],
'value' => function ($model) {
return $model->price;
},
'filter' => Category::getPrices(),
'format' => 'raw'
],
[
'class'=>'kartik\grid\EditableColumn',
'attribute' => 'expire_days',
'editableOptions'=>[
'header'=>' ',
'inputType'=>\kartik\editable\Editable::INPUT_SPIN,
'options'=>['pluginOptions'=>['min'=>0, 'max'=>100]]
],
'value' => function ($model) {
return $model->expire_days;
},
'filter' => Category::getExpDays(),
'format' => 'raw'
],
]
控制器:
if (Yii::$app->request->post('hasEditable')) {
$model = new Category();
$id = Yii::$app->request->post('editableKey');
$model = Category::findOne($id);
$out = Json::encode(['output'=>'', 'message'=>'']);
$post = [];
$posted = current($_POST['Category']);
$post['Category'] = $posted;
if ($model->load($post)) {
$model->price = $post['Category']['price'];
$model->expire_days = $post['Category']['expire_days'];
$model->save();
$output = '';
$out = Json::encode(['output'=>$output,'message'=>'']);
}
echo $out;
return;
}
答案 0 :(得分:0)
您应该分别处理两种情况:
Range.prototype._pointerDown = function (ev) {
if (this._disabled) {
return false;
}
//Emit ion start event to run the timer for collecting of slider move
this.ionStart.emit(this);
.
.
.
.
};
如果您收到价格-您仅更新价格。如果您收到expire_days-请更新expire_days。