【问题标题】:How make drop down selected in blade template in Laravel 4.1?如何在 Laravel 4.1 的刀片模板中选择下拉菜单?
【发布时间】:2014-01-26 02:18:38
【问题描述】:

我正在尝试显示所有国家/地区的下拉列表。在编辑页面中,我想选择一个国家。将India 称为selected=selected。

<div class="large-3 columns">
    {{ Form::label('country') }}
</div>
<div class="large-4 columns">
    @include("common.country")
</div>

我该怎么做。是否可以在@include("common.country") 中传递数组中的值?

【问题讨论】:

  • 您能发布包含视图的内容吗?
  • @DamienPirsy: @section("country") @if (count($countries) &gt; 0) {{ Form::select('country', $countries, null, array('id' =&gt; 'country')); }} @endif @show

标签: php laravel-4 template-engine blade


【解决方案1】:
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');

这里默认选择小。我们可以在末尾添加默认选中项。 Drop-Down Lists

【讨论】:

  • 其实说@include("common.country")是在视图中生成select标签。
  • {{ Form::select('country', $countries, null, array('id' => 'country')); }} 这里第一个参数国家是名称,第二个是国家列表的数组。第三个参数是选择的默认值。但这里它是空的。
  • 我同意 Praveen,但在视图页面中不使用表单标签。仅使用@include("common.country"),它将显示所有国家/地区的下拉列表。
  • 您可以将其添加到包含的视图中
【解决方案2】:

就像在发布国家/地区的“变量”之后写下您想要的默认国家/地区名称一样简单,作为“刀片”参数。

{{ Form::select('country', $countries, 'Palestine', ['id' => 'countrySelector', 'class' => 'formElement']) }}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2018-02-16
    • 2014-04-03
    • 2016-12-18
    • 2013-04-29
    相关资源
    最近更新 更多