Php 使用Yii ESelect2扩展名在ESelect2下拉列表中选择多个值
我在表格中使用此选项:Php 使用Yii ESelect2扩展名在ESelect2下拉列表中选择多个值,php,yii,Php,Yii,我在表格中使用此选项: $this->widget('ext.select2.ESelect2',array( 'model'=>$model, 'attribute'=>'Employee', 'data'=>$model->Employee, 'options'=>array( 'width'=>'210','placeholder'=>'All Offices', ), 'htmlOptions' => a
$this->widget('ext.select2.ESelect2',array(
'model'=>$model,
'attribute'=>'Employee',
'data'=>$model->Employee,
'options'=>array(
'width'=>'210','placeholder'=>'All Offices',
),
'htmlOptions' => array(
'multiple' => 'multiple'
),
));
$model->Employee
是一个数组,当我移动以更新数据时,我希望在数据中选择此数组,就像下拉属性selected=“selected”
Select2使用预定义值填充自身一样。但是这些必须在model属性中。如果是多个,则$model->Employee
应该是一个数组:
$model->Employee = array(1=>'Allen', 2=>'John'); // or similar
此外,此处的key=>value
应以与员工模型数据相同的方式进行映射
然而,“data”参数仍然应该包含范围内的所有数据
因此,试试这个,其中Employee
应该是包含所有数据选项的模型:
更新
我在选项中添加了标记,如和所示
$model->Employee是一个数组。但此数组将数据引入此下拉列表的选项,但不显示为选定元素。但不工作,标记元素将其形状更改为经典。它仅建议数据,但不显示为选定值。
$tags= array(1=>'Allen', 2=>'John');
$this->widget('ext.select2.ESelect2',array(
'model'=>$model,
'attribute'=>'Employee',
'data'=> Chtml::listData(Employee::model()->findAll(), 'id', 'name'),
'options'=>array(
'width'=>'210','placeholder'=>'All Offices',
'tags'=>$tags,
),
'htmlOptions' => array(
'multiple' => 'multiple'
),
));