我有2 SELECT2下拉列表第二取决于数据从第一个Yii2:卡尔蒂克选择二
第一个代码:
<?= $form->field($model, 'patient_id')->widget(select2::className(),[
'data'=> arrayhelper::map(patient::find()->all(),'patient_id','patient_name'),
'options'=>['placeholder'=>'select patient Name ... '],
'pluginOptions'=>[
'allowClear'=>true
],
])?>
第二个代码:
<?= $form->field($model, 'doctor_id')->widget(select2::className(),[
'data'=> arrayhelper::map(doctors::find()->all(),'doctor_id','doctor_name'),
'options'=>['placeholder'=>'أختر اسم الطبيب '],
'pluginOptions'=>[
'allowClear'=>true
],
])?>
我知道第二个sql代码是:
从医生
选择doctor_name所以我需要它是:
选择从医生DISTINCT doctor_name其中doctor_id在(从patient_services SELECT doctor_id WHERE patient_id = “FROM THE第一DROPDOWNLIST值”)
在正常的下拉列表中它像这样工作Yii2 Lesson - 20 Dependent Drop Down Lists By DoingITeasyChannel但在select2中我没有找到如何去做。
-------------------------------更新后----
的意见有DepDrop但我很困惑如何使用它。
我已经改变
<?= $form->field($model, 'patient_id')->widget(Select2::classname(), [ 'data' => ArrayHelper::map(patient::find()->asArray()->all(), 'patient_id', 'patient_name')]); ?>
并且另一个是:
<?= $form->field($model, 'doctor_id')->widget(DepDrop::classname(), [ 'options' => ['placeholder' => 'Select ...'], 'type' => DepDrop::TYPE_SELECT2, 'select2Options'=>['pluginOptions'=>['allowClear'=>true]], 'pluginOptions'=>[ 'depends'=>['receipts-doctor_id'], // here i got confused 'url' => Url::to(['/receipts/child']), 'loadingText' => 'Loading child level 1 ...', ] ]); ?>
在控制器
public function actionChild() { $out = []; if (isset($_POST['depdrop_parents'])) { // what they meaning by depdrop_parents or what i should change it ?
$id = end($_POST['depdrop_parents']); $list = Account::find()->andWhere(['parent'=>$id])->asArray()->all(); $selected = null; if ($id != null && count($list) > 0) { $selected = ''; foreach ($list as $i => $account) { $out[] = ['id' => $account['id'], 'name' => $account['name']]; if ($i == 0) { $selected = $account['id']; } } // Shows how you can preselect a value echo Json::encode(['output' => $out, 'selected'=>$selected]); return; } } echo Json::encode(['output' => '', 'selected'=>'']); }
您可以使用[卡尔蒂克DepDrop(http://demos.krajee.com/widget-details/depdrop) –
要添加到什么@InsaneSkull建议您可以使用DepDrop插件,并仍然使用Select2,因为DepDrop插件支持Select2下拉菜单。你必须使用'type'选项。 – sm1979
@InsaneSkull谢谢..我没有看到过这个,,,我看见了,我有一些问题'“依赖” => [“帐户LEV0”],'我没有得到它,我有父ID是'patient_id'有是别的东西,我在控制器代码糊涂了'$名单=帐户::发现() - > andWhere([ '父'=> $ ID]) - > asArray() - >所有();' –