0
我从表中通过javascript获得了一行,并在Productnames
控制器中执行了操作。通过javascript在yii2中获取相关模型
我得到的领域,是的productid,产品名称和bottletype。到目前为止,没关系。
JS
<?php
$script = <<< JS
$('#catid').change(function(){
var catid = $(this).val();
$.get('index.php?r=production/productnames/get-for-production',{ catid : catid }, function(data){
alert(data.unitprice);
// var data = $.parseJSON(data);
// $('#productnames-bottletype').attr('value',data.bottletype)
});
});
JS;
$this->registerJs($script);
?>
在ProductnamesController
public function actionGetForProduction($catid)
{
$bottle = Productnames::findOne(['productnames_productname'=>$catid]);
//$bottle -> select(['productnames.productnames_productname','productnames.bottletype','bottlename.unitprice'])->from('Productnames')->leftJoin('bottlename','productnames.bottletype = bottlename.bottlename')->where(['productnames_productname'=>$catid])->limit(1);
echo Json::encode($bottle);
}
行动现在我想从有关产品名称表作为productname.bottletype = bottlename.bottlename
bottlename表中获取数据。
表bottlename
有3个域:
ID,bottlename,单价。
我越来越产品名称,bottlename从上面提到的代码。 W 我想要的帽子是获得单位价格以及上述数据。
下面是截图什么,我现在越来越:
它没有显示在输出中的“单价”字段。输出结果与以前相同 – Tanmay
正常工作。非常感谢。 – Tanmay