选项标签不使用select2在laravel 5.1中显示默认选择的选项

时间:2016-01-07 06:10:12

标签: php html drop-down-menu laravel-5.1

我在select2中遇到了一个奇怪的问题。我想要显示的默认选项没有发生。如果光标放在相关的select2框上,它会在图像中显示所需的值作为'alt'属性那么事情就是将值传递给select2框,但它没有显示!这是我的代码:

<div class="row">
<?php
$country = explode('_', $patron_address['country']);
$countryId = $country[0];
$countryCode = $country[1];
$countryName = $country[2];
?>
   <div class='col-md-6'>
      <div class="form-group{!! ($errors->has('country'))? ' has-error':'' !!}">
         <label for="country" class="control-label col-md-3"> Country <span class="required" aria-required="true">*</span> </label>
         <div class="col-md-8">
            <select name="country" id="select2_country" class="form-control">
               <option></option>
               @if($country)
               <option value="{!! $countryName !!}" selected="selected">{!! $countryName !!}</option>
               @endIf
            </select>
            @if ($errors->has('country')) <span class="help-block">{!! $errors->first('country') !!}</span> @endif </div>
      </div>
      `enter code here` </div>
</div>

即使代替{!! $ countryName !!},如果我使用任何硬编码选项显示,同样的问题仍然存在。 这是在laravel 5.1中完成的。 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

你可以检查$ patron_address ['country']的值,因为我发现以下代码工作正常

<div class="row">
<?php
$country = explode('_', 'test1_test2_test3');
$countryId = $country[0];
$countryCode = $country[1];
$countryName = $country[2];
?>
   <div class='col-md-6'>
      <div class="form-group{!! ($errors->has('country'))? ' has-error':'' !!}">
         <label for="country" class="control-label col-md-3"> Country <span class="required" aria-required="true">*</span> </label>
         <div class="col-md-8">
            <select name="country" id="select2_country" class="form-control">
               <option></option>
               @if($country)
               <option value="{!! $countryName !!}" selected="selected">{!! $countryName !!}</option>
               @endIf
            </select>
            @if ($errors->has('country')) <span class="help-block">{!! $errors->first('country') !!}</span> @endif </div>
      </div>
      `enter code here` </div>
</div>