问题描述
我在Create-Service-Form
中的Staff
中有一个multiple select-list-box
,用于在创建新服务时选择多个人员.为此,我可以在一项服务上分配多名员工.
I have a multiple select-list-box
for Staff
in Create-Service-Form
, used to select multiple staff when creating a new service. for this i can assign multiple staff on a single service.
我将staff_id
字段另存为:
$model->staff_id = serialize($model->staff_id);
这是用于多选列表框的更新视图代码:
<div class="row">
<?php echo $form->labelEx($model,'staff_id'); ?>
<?php
$data = array('1' => 'Sam', '2' => 'john', '3' => 'addy');
$htmlOptions = array('size' => '5', 'prompt'=>'Use CTRL to Select Multiple Staff', 'multiple' => 'multiple');
echo $form->ListBox($model,'staff_id', $data, $htmlOptions);
?>
<?php echo $form->error($model,'staff_id'); ?>
</div>
问题是,当我加载用于更新服务的表格时.我该如何选择以前保存在数据库中的人员?
Problem is, when i load form for updating a service. how do i select those staff, which are previously saved in database?
我尝试了此 dropDownList属性,但没有工作.
$ select |字符串|选定的值
I tried this dropDownList-attributes, but it not working.
$select | string | the selected value
如果有人有解决方案,那么建议我.谢谢所有伴侣...
if someone has solution, then suggest me. Thanks All Mates...
推荐答案
这是我为您编写的快速代码,它是一个示例,可帮助您了解其工作原理.
Here's a quick code I wrote for you, its an example that will help you understand how it works.
<div class="row">
<?php echo $form->labelEx($model,'staff_id'); ?>
<?php
$data = array('101' => 'Faraz Khan', '102' => 'Depesh Saini', '103' => 'Nalin Gehlot', '104' => 'Hari Maliya');
$selected = array(
'102' => array('selected' => 'selected'),
'103' => array('selected' => 'selected'),
);
$htmlOptions = array('size' => '5', 'prompt'=>'Use CTRL to Select Multiple Staff', 'multiple' => 'true', 'options' => $selected);
echo $form->listBox($model,'staff_id', $data, $htmlOptions);
?>
<?php echo $form->error($model,'staff_id'); ?>
</div>
玩得开心呀!
这篇关于如何在yii的更新视图中的多选列表框中加载选定的列表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!