为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
青春有我 2023-04-21 10:02:42
我有一个问题。我有 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]) ?>
查看完整描述

1 回答

?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

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


<?=$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 个字段中使用相同的结果。


查看完整回答
反对 回复 2023-04-21
  • 1 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信