Laravel 4 Blade 下拉列表类属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18530975/
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
Laravel 4 blade drop-down list class attribute
提问by Gravy
Laravel blade drop down list class attribute not working.
Laravel 刀片下拉列表类属性不起作用。
I cannot find any reference to class or assigning attributes to select / drop-down lists in the documentation.
我在文档中找不到任何对类或分配属性以选择/下拉列表的引用。
http://www.laravel.com/docs/html#drop-down-lists
http://www.laravel.com/docs/html#drop-down-lists
Examples tried:
尝试的示例:
{{ Form::select('product_id', $productList, array('class'=>'form-control')) }}
{{ Form::select('product_id', $productList, $attributes = array('class'=>'form-control')) }}
Both return the same html but without the class
attribute:
两者都返回相同的 html 但没有class
属性:
<select id="product_id" name="product_id">
... Option Stuff ...
</select>
回答by Bastian Hofmann
{{ Form::select('product_id', $productList, null, array('class' => 'form-control')) }}
The third parameter is the key of the currently selected option. Defaults to null.
第三个参数是当前选中选项的key。默认为空。
回答by DolDurma
First get and create list in Controller for example:
首先在 Controller 中获取并创建列表,例如:
$username_lists = Users::lists('username','id');
pass data to view by:
传递数据以查看:
return View::make('layouts.customers')
->with('username_lists', $username_lists);
now get in view:
现在进入视图:
{{ Form::select('username_lists', $username_lists, null, array('class' => 'form-control')) }}