在yii2的select2下拉列表中设置默认值

时间:2017-12-12 09:03:49

标签: yii2 jquery-select2

我在yii2中有一个kartik select2相关下拉列表,我想选择一个值作为默认选择值。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.calendars.js"></script> 
<script type="text/javascript" src="js/jquery.calendars.plus.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.calendars.picker.css"> 
<script type="text/javascript" src="js/jquery.plugin.js"></script> 
<script type="text/javascript" src="js/jquery.calendars.picker.js"></script>

如何在下拉列表中选择默认值?

1 个答案:

答案 0 :(得分:1)

在控制器中

$EmployeeLeaveModel->EmployeeID = value;

<?= $form->field($EmployeeLeaveModel, 'EmployeeID')->widget(Select2::classname(), [
     'data' => $Employee,
     'language' => 'en',
     'options' => ['placeholder' => 'Select Employee,...'],   
]) ?>

在视图中

recyclerView.sethasFixedSize(true);