我是一個新的Yii2。我有這個錯誤,我不知道如何解決這個問題。Bug 很簡單,templateSelection 調用了兩次。這是我的代碼。如果我在 select2 中提交某些內容,則 templateSelection 會調用兩次。echo Select2::widget([ 'name' => 'blogId', 'options' => ['placeholder' => 'Search for [![enter image description here][1]][1] ...'], 'pluginOptions' => [ 'allowClear' => true, 'minimumInputLength' => 1, 'ajax' => [ 'url' => Url::to(['/controller/action']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }'), 'processResults' => new JsExpression($resultsJs), ], 'templateResult' => new JsExpression($formatRepo), 'templateSelection' => new JsExpression('function(params) { console.log("tst");}'), ], ]);謝謝您的幫助。
1 回答

三國紛爭
TA貢獻1804條經驗 獲得超7個贊
我通過調試 select2.full.js 找到了自己的響應
問題就在這里。只需刪除此代碼。它調用了兩次,因為它是嵌套函數。
this.$element.on('change.select2', function () { self.dataAdapter.current(function (data) {
//self.trigger('selection:update', {
data: data });
// });
});
- 1 回答
- 0 關注
- 138 瀏覽
添加回答
舉報
0/150
提交
取消