Yii2 - 只有一个选择获取选项

我有一个问题。我有 3 个选择输入,我想用相同的选项填充。第一个输入获得选项,但另外两个没有。我已经尝试了一切。最后一件事,我尝试的是选择 3 个不同的查询并分别填写每个查询。不幸的是,我遇到了同样的问题。


感谢您的建议。


控制器


$dataPbxObj1 = Sipend::find()

        ->select('cc_sip_end.*')

        ->leftJoin('cc_reseller_to_pbx', '`cc_reseller_to_pbx`.`ID_PBX` = `cc_sip_end`.`id`')

        ->where(["in", "cc_reseller_to_pbx.id_cc_reseller", $reseller->id_cc_reseller])->all();


    $dataPbxObj2 = Sipend::find()

        ->select('cc_sip_end.*')

        ->leftJoin('cc_reseller_to_pbx', '`cc_reseller_to_pbx`.`ID_PBX` = `cc_sip_end`.`id`')

        ->where(["in", "cc_reseller_to_pbx.id_cc_reseller", $reseller->id_cc_reseller])->all();


    $dataPbxObj3 = Sipend::find()

        ->select('cc_sip_end.*')

        ->leftJoin('cc_reseller_to_pbx', '`cc_reseller_to_pbx`.`ID_PBX` = `cc_sip_end`.`id`')

        ->where(["in", "cc_reseller_to_pbx.id_cc_reseller", $reseller->id_cc_reseller])->all();


    $dataPbx1 = ArrayHelper::map($dataPbxObj1,'id','popis');

    $dataPbx2 = ArrayHelper::map($dataPbxObj2,'id','popis');

    $dataPbx3 = ArrayHelper::map($dataPbxObj3,'id','popis');

查看(所有这些选择都相同)


<?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(),

               ["data" => $dataPbx3,'hideSearch' => true]) ?>


青春有我
浏览 94回答 1
1回答

一只斗牛犬

您可能需要使用唯一 ID - 默认情况下 Yii 根据字段名称生成 ID,但是对于 3 个相同的字段,ID 将相同,并且 Select2 init 将仅适用于其中的第一个。<?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(), [&nbsp; &nbsp; 'options' => ['id' => 'ID_PBX1'],&nbsp; &nbsp; 'data' => $dataPbx,&nbsp; &nbsp; 'hideSearch' => true,]) ?><?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(), [&nbsp; &nbsp; 'options' => ['id' => 'ID_PBX2'],&nbsp; &nbsp; 'data' => $dataPbx,&nbsp; &nbsp; 'hideSearch' => true,]) ?><?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(), [&nbsp; &nbsp; 'options' => ['id' => 'ID_PBX3'],&nbsp; &nbsp; 'data' => $dataPbx,&nbsp; &nbsp; 'hideSearch' => true,]) ?>顺便说一句:您不需要查询选项列表 3 次,您可以查询一次并在 3 个字段中使用相同的结果。
打开App,查看更多内容
随时随地看视频慕课网APP