簡體   English   中英

如果使用Select2 YII2選擇了第一個字段,則在下面自動填充字段

[英]Autofill field below if first field is selected using Select2 YII2

我在Yii2上開發HRMS我有這個Displace Employee Form,使用3個表的3個字段,正在替換,雇員和部門,我在Employee字段上使用Kartik / Select2小部件,我開發的數據庫更像這樣
數據庫

如果我想這樣的輸出
輸出量

我該怎么辦 ? 我嘗試了一些這樣的代碼

<?= $form->field($model, 'EmployeeId')->widget(Select2::classname(), 
[
'data'=>$listData,
'options' => ['id' => 'EmployeeId'],
'pluginOptions' => [
                    'placeholder' => 'Employee Name',
                    'changeOnReset'=>'$.post
                ("index.php?r=project/lists&id='.'"+$(this).val(),function(data) 
                    { $("select#currentDept").html(data);
                    }
                );'
                   ],
                   ])?>
<?= $form->field($model, 'currentDept')->dropDownList($dataList,['prompt'=>'Choose Department','readonly' => !$model->isNewRecord]) ?>
<?= $form->field($model, 'DeptID')->dropDownList($dataList,['prompt'=>'Choose Department']) ?>

它有效,但是CurrentDept字段未生成

請檢查此鏈接: http : //demos.krajee.com/widget-details/select2 您可以使用“ pluginEvents”。

pluginEvents = [
    "change" => "function() { log('change'); }",
    "select2:opening" => "function() { log('select2:opening'); }",
    "select2:open" => "function() { log('open'); }",
    "select2:closing" => "function() { log('close'); }",
    "select2:close" => "function() { log('close'); }",
    "select2:selecting" => "function() { log('selecting'); }",
    "select2:select" => "function() { log('select'); }",
    "select2:unselecting" => "function() { log('unselecting'); }",
    "select2:unselect" => "function() { log('unselect'); }"
];

您可以使用select事件,並使用回調函數填充其他字段。 讓我知道您是否需要進一步的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM