yii2中的dependendt dropdownlist

yii2中的dependendt dropdownlist,yii2,dropdown,Yii2,Dropdown,您的代码有点乱,在php中编写js时可能会被发现错误,其中excape序列必须完全相同。我已经重新做了工作。让我知道它是否有效 <?= $form->field($model, 'fk_int_category_id')->dropDownList( ArrayHelper::map(TblCategory::find()->all(), 'pk_category_id','vchr_category_name'), ['p

您的代码有点乱,在php中编写js时可能会被发现错误,其中excape序列必须完全相同。我已经重新做了工作。让我知道它是否有效

<?= $form->field($model, 'fk_int_category_id')->dropDownList(
            ArrayHelper::map(TblCategory::find()->all(), 'pk_category_id','vchr_category_name'),
            ['prompt'=> 'Select a category',
             'onchange'=>'
                    $.post("index.php?r=product-size-variants/get-sub-category&id='.'"+$(this).val(), function(data){
                        //alert(data);
                            $("select#tblproduct-fk_int_sub_category_id").html(data);
                    });',       
            ]) ?>

    <?= $form->field($model, 'fk_int_sub_category_id')->dropDownList(
            ArrayHelper::map(TblSubCategory::find()->all(), 'pk_sub_category_id','vchr_sub_category_name'),
            ['prompt'=> 'Select Sub category'
              'onchange'=>'
                    $.post("index.php?r=product-size-variants/get-sub-category&subId='.'"+$(this).val(), function(data){
                        //alert(data);
                            $("select#tblproduct-fk_int_sub_category_id").html(data);
                    });'  
            ]) ?>

    <?= $form->field($model, 'fk_int_product_variants')->dropDownList(
            ArrayHelper::map(TblProductSizeVariants::find()->all(), 'pk_int_product_size_variants_id','vchr_size_names'),
            ['prompt'=> 'Select Product Size']) ?>

函数生成子类(obj){

$.post(“index.php?r=产品尺寸变量/get sub-category/?id=“+obj.value,函数(数据)){ $(“选择#tblproduct-fk#int#U sub#U category#U id”).html(数据); }); } 函数生成器产品变量(obj){ var catID=$('#tblproduct-fk_int_category_id').val(); 如果(catID==“”){ 警告(“请选择类别”); }否则{
$.post(“index.php?r=产品尺寸变量/get sub-category/?id=“+catID+”&subId=“+obj.value,函数(数据){ $(“选择#tblproduct-fk#int#U sub#U category#U id”).html(数据); }); } }
请参考以下url,以了解可帮助您的相关下拉列表


index.php?r=产品尺寸变量/获取子类别?firstKey=firstValue&secondkey=secondvalue&thirdKey=thirdValue。。。。以此类推。好的。但是这里我如何在第二个下拉列表中得到第一个下拉列表id值
<?= $form->field($model, 'fk_int_category_id')->dropDownList(
        ArrayHelper::map(TblCategory::find()->all(), 'pk_category_id','vchr_category_name'),
        ['prompt'=> 'Select a category',
         'onchange'=>'generateSubCat(this)',       
        ]) ?>

<?= $form->field($model, 'fk_int_sub_category_id')->dropDownList(
        ArrayHelper::map(TblSubCategory::find()->all(), 'pk_sub_category_id','vchr_sub_category_name'),
        ['prompt'=> 'Select Sub category'
          'onchange'=>'generateProductVariant(this)'  
        ]) ?>

<?= $form->field($model, 'fk_int_product_variants')->dropDownList(
        ArrayHelper::map(TblProductSizeVariants::find()->all(), 'pk_int_product_size_variants_id','vchr_size_names'),
        ['prompt'=> 'Select Product Size']) ?>

<script>
function generateSubCat(obj){
     $.post("index.php?r=product-size-variants/get-sub-category/?id="+obj.value, function(data){
        $("select#tblproduct-fk_int_sub_category_id").html(data);
    });
  }
 function generateProductVariant(obj){
    var catID=$('#tblproduct-fk_int_category_id').val();
    if(catID==""){
       alert("Please select category");
    }else{
        $.post("index.php?r=product-size-variants/get-sub-category/?id="+catID+"&subId="+obj.value, function(data){
            $("select#tblproduct-fk_int_sub_category_id").html(data);
        });
     }

  }
  </script>