templateSelection 调用了两次 (Select2 Kartik- yii2)
templateSelection called two time (Select2 Kartik- yii2)
我是新手Yii2.I有这个问题,我不知道如何解决这个问题。
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");}'),
],
]);
感谢您的帮助。
我自己通过调试找到了响应 select2.full.js
问题就在这里。
只需删除此代码。它调用了两次,因为它是嵌套函数。
this.$element.on('change.select2', function () { self.dataAdapter.current(function (data) {
//self.trigger('selection:update', {
data: data });
// });
});
我是新手Yii2.I有这个问题,我不知道如何解决这个问题。
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");}'),
],
]);
感谢您的帮助。
我自己通过调试找到了响应 select2.full.js
问题就在这里。 只需删除此代码。它调用了两次,因为它是嵌套函数。
this.$element.on('change.select2', function () { self.dataAdapter.current(function (data) {
//self.trigger('selection:update', {
data: data });
// });
});