Laravel 中的多选下拉菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24821567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple select dropdown in laravel
提问by user3714121
Here is my code in the view, I want to display a dropdown that contains the selected data in an edit view.
这是我在视图中的代码,我想在编辑视图中显示一个包含所选数据的下拉列表。
{{Form::select('Select_targets[]', $_targets,Input::old('Select_target', $profile->Target_idTarget-1), array('multiple' => true))}}
I tried this code but it just displays one selected value. Please I need your help! Thanks in advance
我试过这段代码,但它只显示一个选定的值。拜托我需要你的帮忙!提前致谢
回答by Bj?rn
I think you have an error around your old input and default values for the dropdown. Here is a stripped down example that does work:
我认为您的旧输入和下拉菜单的默认值有误。这是一个确实有效的精简示例:
Controller:
控制器:
//current selected
$target = 3;
/array with options
$targets[1] = 'target 1';
$targets[2] = 'target 2';
$targets[3] = 'target 3';
return View::make('form')->with('targets',$targets)->with('target',$target);
View:
看法:
{{ Form::open() }}
{{ Form::select('targets[]', $targets, Request::old('targets') ? Request::old('targets') : $target, array('multiple' => true)); }}
{{ Form::submit('send') }}
{{ Form::close() }}