【发布时间】:2017-03-20 02:41:18
【问题描述】:
如果很快存在,我想根据 $_GET 选择值。
这是我的代码
<?php
/*if ($model->isNewRecord && !isset($model->agent_id_upper)) {
$model->agent_id_upper = 65;
} not working too*/
//$model->agent_id_upper = 65; ->not working
echo Select2::widget([
'model' => $model,
'name' => 'TbAgent[agent_id_upper]',
//'id' => 'to_id',
'initValueText' => '', // this only for ajax
'data' => $data,
'options' => [
'placeholder' => 'Choose Agent ...',
'multiple' => false,
//'selected' => 65, -> not working
//'value' => 65, -> not working
'class' => ''
],
]
);
?>
65 是记录的 ID,如果选中则应显示该 ID 的用户名。
但我的问题是没有选择 65 的用户名,它只显示占位符。
我该如何解决这个问题?并请给我参考。
已经读过了
yii2 select2 by kartik-v set default value
Yii2: Kartik Select2: Initial Value from Model Attribute
http://www.yiiframework.com/forum/index.php/topic/52278-kartik-select2-not-select-corretly/
但上面没有运气。
提前致谢。
【问题讨论】: