【发布时间】:2020-10-11 23:24:46
【问题描述】:
我正在使用Yii2,我有两个表和两个模型:
table 1: tenderprice:(id, itemname, quanity)(id is primary key) 型号名称=Tenderprice,表 2:tenderpricelist:id pk,singleprice, totalprice,tenderpriceid: (tenderpriceid is foreign key refers to Tenderprice) 型号名称:Tenderpricelist
现在我想要选择 itemname 时的数量:
<?
$itemtenders=Tenderprice::find()->all();
$itemlist=ArrayHelper::map($itemtenders,'id','itemname');
echo $form->field($model, 'tenderpriceid')->dropDownList($itemlist,['prompt'=>'Select tender'])->hint('Please choose item one by one')->label('Add Items');
?>
// inserting data into tenderpricelist based on the selection of table tenderprice
<?= $form->field($model, 'singleprice')->textInput(['maxlength' => true])->hint('Please enter your price') ?>
<?= $form->field($model, 'totalprice')->textInput(['maxlength' => true])
?>
现在我想基于从DropdownList中选择的项目名称将数据插入员工名称。DropdownList正确填写,但在选择itemName时,我无法访问“数量”列的值。 我只想当我从下拉列表中选择项目名称时,其相应的数量将显示在文本框或标签上,并且我的表招标价格列表中的总价格列将是:总价格
totalprice=quantity *singleprice
注意:singleprice在表tenderpricelist中,而数量在父表tenderprice中。
【问题讨论】:
标签: yii yii2 yii2-advanced-app yii-extensions yii2-model