我使用laravel collective htmlServiceProvider
填充了我的Select选项<div class="col-md-6">
{!! Form::label('Serial' ,null,['class'=>'small']) !!}
{!! Form::select('cross_match_id',$serials,null,['class'=>'select2 input-sm form-control','id'=>'cross_match_id']) !!}
</div>
我使用Jquery
从数据库设置了默认值$('#cross_match_id').val(data.cross_match_id);
如果我不使用select2,则会设置默认值和值的文本。但是当我使用Select2时它只是空的。虽然我可以看到它有默认值但没有设置。
如何使用select2
设置默认值和文本答案 0 :(得分:2)
您必须在设置值
之后使用change
触发器在select2中进行更新
$('#cross_match_id').val(data.cross_match_id).change();
答案 1 :(得分:0)
试试这个:
// to select the first blank value
("#id").select2().select2("val", null);
// to select specific value
$("#id").select2().select2("val", 'oneofthevaluehere');