简体   繁体   English

如何在下拉菜单中显示值?

[英]How Can I Display Value in Dropdown?

I want to display a value in a drop-down whenever I edit content, but I don't know how can I show it. 每当我编辑内容时,我都希望在下拉列表中显示一个值,但是我不知道如何显示它。 Can someone help me with this? 有人可以帮我弄这个吗?

Dropdown 落下

Here I have a dropdown that has the value of the country when I insert it to the database. 在这里,有一个下拉列表,其中包含将国家/地区插入数据库中时的国家/地区值。 But when I edit the drop-down, the country saved will be removed. 但是,当我编辑下拉菜单时,保存的国家/地区将被删除。

{{ Form::select('from_location', trans('countries'), null, ['class' => 'form-control', 'placeholder' => 'Select where you From']) }}

Update Controller 更新控制器

$aircraftFlights = Aircraft::find($id);
$aircraftFlights ->destination= $request->input('destination');
$aircraftFlights ->save();

You are passing null into field for current value. 您正在将null传递给当前值的字段。

Try this: 尝试这个:

{{Form::select('from_location', trans('countries'), !empty($aircraftFlights) ? $aircraftFlights->destination : null ,['class' => 'form-control', 'placeholder' => 'Select where you From'])}}<br>

You can refer here for more details: 您可以在此处参考以获取更多详细信息:

https://laravelcollective.com/docs/5.4/html#drop-down-lists https://laravelcollective.com/docs/5.4/html#drop-down-lists

Hope this helps 希望这可以帮助

{{Form::select('from_location', trans('countries'),null,['class' => 'form-control', 'placeholder' => 'Select where you From', 'value' => $your_value_here])}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据下拉菜单中的选择显示表格值? - How can I display a table value based on the selection from a dropdown? 如何获得我单击以显示在下拉列表下方的下拉值 - How can I get a dropdown value I click on to display below the dropdown 如何在下拉字段中显示JavaScript值? - How do I display a javascript value in dropdown field? 如何在按钮中显示下拉列表的选定元素? - How can I display the selected element of a dropdown list in a button? 我如何从数据库中检索数据并将其显示在“选择”下拉列表中 - how can i retrive data from database and display it in a Select dropdown 如何在 BackboneJS 中显示 Model 属性的 select 列表(下拉列表)? - How can I display a select list (dropdown) for a Model property in BackboneJS? 无法选择下拉列表值,选择每个下拉列表后如何显示动态字段? - Not able to select the dropdown value and How do I display the dynamic field after selecting each dropdown? 如何在jsp中显示选定年份(年份)和月份(月份)中的所有日历日期? - How can I display all the calendar dates in jsp, for a selected year in years dropdown and selected month in months dropdown? 如何显示输入值? - How can I display the input value? 如何使用Ajax显示值 - How can I display the value using ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM