【问题标题】:templateSelection called two time (Select2 Kartik- yii2)两次调用模板选择(Select2 Kartik-yii2)
【发布时间】:2020-06-30 09:35:11
【问题描述】:

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

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");}'),
                            ],

                        ]);

感谢您的帮助。

【问题讨论】:

    标签: php yii2 jquery-select2 kartik-v


    【解决方案1】:

    我通过调试 select2.full.js 找到了自己的响应

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

        this.$element.on('change.select2', function () { self.dataAdapter.current(function (data) { 
    //self.trigger('selection:update', { 
    data: data }); 
    // }); 
    });
    

    【讨论】:

      猜你喜欢
      • 2017-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2017-08-15
      • 1970-01-01
      • 2016-07-14
      相关资源
      最近更新 更多