如何在 yii 中设置 yii-select2 中的预选数据,就像这个例子
http://ivaynberg.github.io/select2/index.html#locked-selections
这是我的代码,我想为预选数据显示另一个数组
$this->widget('bootstrap.widgets.TbSelect2', array(
'asDropDownList' => false,
'name' => 'YumProfile[projectlist]',
'options' => array(
'multiple' => true,
'data' => $array,
'width' => '40%',
'tokenSeparators' => array('##', ' ')
)));
最佳答案
好像在用 YiiBooster。我希望你试试这个:
$array = array(
'active' => 'Active',
'pending' => 'Pending',
'invited' => 'Invited',
'deleted' => 'Deleted'
)
$this->widget('bootstrap.widgets.TbSelect2', array(
'asDropDownList' => false,
'name' => 'YumProfile[projectlist]',
'data' => $array,
...
'htmlOptions' => array(
'options' => array( // selected options by default
'active' => array(
'selected' => true,
)
)
),
)
);
我也对 Yii Select2 Extension 做了同样的事情, 但方法略有不同。
关于twitter-bootstrap - yii select2 插件预加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17765641/