我正在使用Yii2-advanced-template。我的表单上有2个部门,如下所示 - 当我点击第2个div中的任何单选按钮时,相应条目的详细信息应加载到第1个div中。也就是说,1st div中的表单将保持不变,但会为更新操作加载一些值。但我得到它 - 这不是我所期望的。它正在该div中加载整个页面布局。
我已经使用过' renderPartial()'在我的控制器中。但它只解决了问题的一半,即导航栏&使用renderPartial()后隐藏其他布局。
我的表单如下 -
<div class="col-sm-12">
<div class="col-sm-6 fillitemform">
...
Enter Item Details form
...
</div>
<div id="item_details" class="col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Item details</h3>
</div>
<div class="panel-body">
<div class="table-responsive" >
<table class="table">
<thead>
<tr><th></th>
<th>PO No.</th>
<th>SKU</th>
<th>Order Type</th>
<th>Expected Qty</th>
<th>Received Qty</th>
<th>Weight</th>
</tr>
</thead>
<tbody>
<?php
for($itr = 0, $ro = $modelRO, $rod = $modelROD; $itr < count($modelROD); ++$itr){
echo '<tr onclick="placeitemdtls('.$rod[$itr]['id'].')">';
echo '<td><input type="radio" name="item"></td>';
echo '<td>'.$ro[0]['ro_po_no'].'</td>';
echo '<td>'.$rod[$itr]['rod_sku'].'</td>';
echo '<td>'.$ro[0]['ro_order_type_id'].'</td>';
echo '<td>'.$rod[$itr]['rod_expected_qty'].'</td>';
echo '<td>'.$rod[$itr]['rod_received_qty'].'</td>';
echo '<td>'.$rod[$itr]['rod_weight'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
我的JS / jQuery函数 -
function placeitemdtls(id){
$.post("index.php?r=receiving-order-details/update&id="+id, function(response) {
jQuery(".fillitemform").html(response);
});
}
我的控制器功能 -
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelRO = ReceivingOrders::find()->where(['id' => $id])->all();
$modelROD = ReceivingOrderDetails::find()->where(['receiving_order_id' => $id])->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['create', 'id' => $id]);
} else {
return $this->renderPartial('update', [
'model' => $model, 'modelRO' => $modelRO, 'modelROD' => $modelROD,
]);
}
}