Laravel 4 - 将 ID 值添加到下拉选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17027806/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:56:00  来源:igfitidea点击:

Laravel 4 - Adding ID values to dropdown selects

laravellaravel-4

提问by BigJobbies

Im trying to use the built in dropdown HTML helper, but i cant find how to add the id="idvalue"

我试图使用内置的下拉 HTML 帮助程序,但我找不到如何添加 id="idvalue"

The documentation give this example,

文档给出了这个例子,

echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));

When i try the following code, i get errors

当我尝试以下代码时,出现错误

echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'id' => 'idvalue');

Im using Laravel 4.

我使用 Laravel 4。

Any help would be greatly appreciated.

任何帮助将不胜感激。

Cheers,

干杯,

回答by Aloys

From the source code of FormBuilder.php:

来自 FormBuilder.php 的源代码:

/**
 * Create a select box field.
 *
 * @param  string  $name
 * @param  array   $list
 * @param  string  $selected
 * @param  array   $options
 * @return string
 */
 public function select($name, $list = array(), $selected = null, $options = array());

So you should call

所以你应该打电话

 echo Form::select('size', array('key' => 'value'), 'default', array('id' => 'ID_HERE'));

回答by Egon T?r?s

The easy answer

简单的答案

echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'L', array('id' => 'idvalue'));

fourth parameter must be an array

第四个参数必须是一个数组

回答by Rockwood

{!! Form::select('designation_id', $designations, old('designation_id'), 
                 ['class' => 'form-control',  'required', 'id' => '#designation']) !!}

you can add like this

你可以这样添加