如何在yii2中使用depdrop

时间:2016-02-17 07:06:14

标签: yii2 yii-extensions yii2-basic-app

我想在yii2

中使用多级依赖下拉列表

这是我的_from:

 <?php $catList=ArrayHelper::map(app\models\NewsCat::find()->all(),'id','news_name');  ?>


    <?= $form->field($model, 'state_id')->dropDownList($catList, ['id'=>'cat_name', 'prompt'=>'Select category']);?>

<?= $form->field($model, 'city_id')->widget(DepDrop::classname(), [
            'options'=>['id'=>'sub_name'], 
            'pluginOptions'=>[
            'depends'=>['cat_name'],
            'placeholder'=>'Select subcategory',
            'url'=>  Url::to(['/opportunity/subcat'])
            ]
            ]);  ?>

这是我的控制者:

 $out = [];
        if (isset($_POST['depdrop_parents']))
            {
            $parents = $_POST['depdrop_parents'];

            if ($parents != null)
                {
                $id = $parents[0];
                $out = \app\models\State::find()->all();


                echo Json::encode(['output' => $out, 'selected' => '1']);
                return;
                }
            }
        echo Json::encode(['output' => '', 'selected' => '']);

$ out有数据,但我无法将数据传递给形成!

 $dropdown in yii2

http://plugins.krajee.com/dependent-dropdown

0 个答案:

没有答案