在多选下拉列表中显示选定的选项 - Yii2
Show selected options in multiselect dropdownlist - Yii2
我正在使用 多选下拉菜单 选择多个选项。直到这个好。但是当我需要在视图页面中显示那些选定的选项时,我被卡住了。
我试过了。
<?
public function getSelectedTodosCaseId($todos_id) {
$case_ids = Todos::find()->select(['case_id'])->where(['todos_id'=> $todos_id])->all();
$selected = [];
if($case_ids){
foreach($case_ids as $case_id){
$selected[] = $case_id->case_id ;
}
}
return $selected;
}
?>
我在这里使用这个功能。
<?php
$selectedCase = $this->getSelectedTodosCaseId($id);
for($i = 0; $i < sizeof($selectedCase); $i++){
$model->t_case_id = $selectedCase[$i];
}
?>
<?= $form->field($model, 't_case_id[]',
['options' =>['class' => ''],'inputOptions'=>['multiple'=>'multiple','size'=>'4']])
->dropDownList($current_user_cases);?>
任何 help/hint 都将是可观的。
In short just remove array(square brackets) from field t_case_id[].
simply give t_case_id, no need it will be automatically converted to
array. ~ @KandarpPatel
$model->t_case_id = $selectedCase;
<?= $form->field($model, 't_case_id',
['options' =>['class' => ''],'inputOptions'=>['multiple'=>'multiple','size'=>'3']])
->dropDownList($current_user_cases)->label("Related to");?>
我没有提供下拉名称 array type
。但是,它是自动转换的。而且,它就像一个魅力。
我正在使用 多选下拉菜单 选择多个选项。直到这个好。但是当我需要在视图页面中显示那些选定的选项时,我被卡住了。
我试过了。
<?
public function getSelectedTodosCaseId($todos_id) {
$case_ids = Todos::find()->select(['case_id'])->where(['todos_id'=> $todos_id])->all();
$selected = [];
if($case_ids){
foreach($case_ids as $case_id){
$selected[] = $case_id->case_id ;
}
}
return $selected;
}
?>
我在这里使用这个功能。
<?php
$selectedCase = $this->getSelectedTodosCaseId($id);
for($i = 0; $i < sizeof($selectedCase); $i++){
$model->t_case_id = $selectedCase[$i];
}
?>
<?= $form->field($model, 't_case_id[]',
['options' =>['class' => ''],'inputOptions'=>['multiple'=>'multiple','size'=>'4']])
->dropDownList($current_user_cases);?>
任何 help/hint 都将是可观的。
In short just remove array(square brackets) from field t_case_id[]. simply give t_case_id, no need it will be automatically converted to array. ~ @KandarpPatel
$model->t_case_id = $selectedCase;
<?= $form->field($model, 't_case_id',
['options' =>['class' => ''],'inputOptions'=>['multiple'=>'multiple','size'=>'3']])
->dropDownList($current_user_cases)->label("Related to");?>
我没有提供下拉名称 array type
。但是,它是自动转换的。而且,它就像一个魅力。