我想在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有数据,但我无法将数据传递给形成!