首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Yii2 -只有一个选择get选项

Yii2 -只有一个选择get选项
EN

Stack Overflow用户
提问于 2020-05-27 11:43:44
回答 1查看 106关注 0票数 0

我有个问题。我有3个选择输入,我想用相同的选项来填写。第一个输入有选项,但另两个没有。我什么都试过了。最后一件事,我尝试的是选择3个不同的查询,并分别填写。不幸的是,我也遇到了同样的问题。

谢谢你的建议。

控制器

代码语言:javascript
复制
$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');

视图(所有这些选择都相同)

代码语言:javascript
复制
<?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(),
               ["data" => $dataPbx3,'hideSearch' => true]) ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-27 12:59:39

您可能需要使用唯一的ID --默认情况下,Yii根据字段名生成ID,但是对于3个相同的字段,ID将是相同的,Select2 init只适用于其中的第一个字段。

代码语言:javascript
复制
<?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(), [
    'options' => ['id' => 'ID_PBX1'],
    'data' => $dataPbx,
    'hideSearch' => true,
]) ?>

<?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(), [
    'options' => ['id' => 'ID_PBX2'],
    'data' => $dataPbx,
    'hideSearch' => true,
]) ?>

<?=$form->field($modelSip, 'ID_PBX')->widget(Select2::className(), [
    'options' => ['id' => 'ID_PBX3'],
    'data' => $dataPbx,
    'hideSearch' => true,
]) ?>

顺便说一句:您不需要查询选项列表3次,只需查询一次,并在3个字段中使用相同的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62042305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档