templateSelection两次调用(Select2 Kartik-yii2)(已解决)

问题描述 投票:0回答:1

我是一个新的Yii2。我有这个错误,我不知道该如何解决这个问题。

错误很简单,两次调用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");}'),
                            ],

                        ]);

谢谢您的帮助。

php yii2 jquery-select2 kartik-v
1个回答
0
投票

我发现已经通过调试select2.full.js做出回应

问题就在这里。只需删除此代码。它调用了两次,因为它是嵌套函数。

    this.$element.on('change.select2', function () { self.dataAdapter.current(function (data) { 
//self.trigger('selection:update', { 
data: data }); 
// }); 
});
© www.soinside.com 2019 - 2024. All rights reserved.