如何在cakephp的mulitiselect列表框中设置选择 [英] How to set selection in mulitiselect list box in cakephp
问题描述
我想将多重选择设置到我的多重列表框中.
I want to set the multi selection to my multi list box.
我的查看页面有两个结果.
I have two results in my view page.
$inr1 = 0;
$arr1 = array();
$str_arr = '';
foreach ($result as $rows){
$inr1 = $rows['Employees']['employee_id'];
$arr1[$inr1] = $rows['Employees']['first_name'].' '.$rows['Employees']['last_name'];
$str_arr = $str_arr.$inr1.',';
}
$str_arr = substr($str_arr,0,-1);
//print_r($arr1);
$inr = 0;
$arr = array();
foreach ($options as $option){
$inr = $option['Employee']['employee_id'];
$arr[$inr] = $option['Employee']['first_name'].' '.$option['Employee']['last_name'];
}
//print_r($arr);
echo $this->Form->input('emp_id_one', array( 'options' => array( $arr),
'empty' => '(choose one)',
'div'=>'formfield',
'error' => array( 'wrap' => 'div',
'class' => 'formerror'
),
'label' => 'Team Members',
'type' => 'select', 'multiple' => true,
'selected' => $arr1,
'style' => 'width:210px; height:125px;',
));
但是$arr1
中的值未在列表框中选择.
But the values in $arr1
not selected in the list box.
$arr1
具有选定的值.
$arr
具有列表的选项.
问题是选择不起作用..没有选择...
The problem is that the selction is not working..There have no selection...
我该怎么做?
如果我的代码有任何问题..?
If there is any problem in my code..?
推荐答案
最后,我通过编写一些代码解决了我的问题:
Finally i solved my problem by chaing some code:
在此$str_arr = substr($str_arr,0,-1);
'之后添加一行代码.
那就是...
Add the one line of code after this $str_arr = substr($str_arr,0,-1);
'.
That is....
$str_arr = substr($str_arr,0,-1);
$sel = explode(',',$str_arr);
然后按如下所示更改变量的名称:
Then change the name of variable as like this :
echo $this->Form->input('emp_id_one', array( 'options' => array( $arr),
'empty' => '(choose one)',
'div'=>'formfield',
'error' => array( 'wrap' => 'div',
'class' => 'formerror'
),
'label' => 'Team Members',
'type' => 'select', 'multiple' => true,
'selected' => $sel,
'style' => 'width:210px; height:125px;',
));
现在在多个列表中选择了$sel
中的值
Now the values in $sel
is selected in the multi list
这篇关于如何在cakephp的mulitiselect列表框中设置选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!