简体   繁体   English

Select2 Uncaught TypeError:无法读取未定义的属性“调用”

[英]Select2 Uncaught TypeError: Cannot read property 'call' of undefined

I am attempting to upgrade from Select2 Version 4.0.7 to 4.0.13 (or anything in between).我正在尝试从 Select2 版本 4.0.7 升级到 4.0.13(或介于两者之间的任何版本)。 When I do I get the following error when clicking on a select box.当我这样做时,单击 select 框时出现以下错误。

Uncaught TypeError: Cannot read property 'call' of undefined
    at r.option (select2.min.js:formatted:489)
    at r.append (select2.min.js:formatted:425)
    at d.<anonymous> (select2.min.js:formatted:530)
    at d.e.invoke (select2.min.js:formatted:289)
    at d.e.trigger (select2.min.js:formatted:283)
    at d.trigger (select2.min.js:formatted:3436)
    at select2.min.js:formatted:3353
    at n.query (select2.min.js:formatted:2138)
    at d.<anonymous> (select2.min.js:formatted:3352)
    at d.e.invoke (select2.min.js:formatted:289)

When I change back to version 4.0.7 everything goes back to working as expected.当我改回版本 4.0.7 时,一切都会按预期工作。 This happens on all of the select2 boxes on the site regardless of the options it is initialized with.这发生在站点上的所有 select2 框上,无论其初始化的选项如何。 I have tried both the full version and the regular versions.我已经尝试过完整版和普通版。

I am using jQuery version 3.5.1我正在使用 jQuery 版本 3.5.1

Update :更新

After further inspection there was some code in the project that was overwriting Window.Element.经过进一步检查,项目中有一些代码覆盖了 Window.Element。 I fixed that code and the below polyfill is no longer needed.我修复了该代码,不再需要下面的 polyfill。

Original Answer :原答案

I'm not sure why but I discovered that I needed to add a polyfill in order to make it work.我不知道为什么,但我发现我需要添加一个 polyfill 才能使其工作。 I am using Chrome Version 87.0.4280.141 (Official Build) (64-bit) but for some reason Element.prototype.matches was returning undefined.我正在使用 Chrome 版本 87.0.4280.141(官方版本)(64 位),但由于某种原因 Element.prototype.matches 返回未定义。 I added the following Polyfill from MDN to fix the issue:从 MDN 添加了以下 Polyfill来解决此问题:

    //Select2 JS Polyfill
    if (!Element.prototype.matches) {
        Element.prototype.matches =
            Element.prototype.matchesSelector ||
            Element.prototype.mozMatchesSelector ||
            Element.prototype.msMatchesSelector ||
            Element.prototype.oMatchesSelector ||
            Element.prototype.webkitMatchesSelector ||
            function (s) {
                var matches = (this.document || this.ownerDocument).querySelectorAll(s),
                    i = matches.length;
                while (--i >= 0 && matches.item(i) !== this) { }
                return i > -1;
            };
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 select2 ajax:未捕获的TypeError:无法读取未定义的属性“上下文” - select2 ajax : Uncaught TypeError: Cannot read property 'context' of undefined 未捕获的类型错误:无法读取未定义的属性“调用” - Uncaught TypeError: Cannot read property 'call' of undefined Select2自定义搜索回调中的“ Uncaught TypeError:无法读取未定义的属性&#39;disabled&#39;” - “Uncaught TypeError: Cannot read property 'disabled' of undefined” in Select2 Custom Search callback 未捕获的TypeError:无法读取select2中null的属性“ replace” - Uncaught TypeError: Cannot read property 'replace' of null in select2 未捕获的TypeError:无法读取null的属性“ getAttribute”(Select2下拉列表) - Uncaught TypeError: Cannot read property 'getAttribute' of null (Select2 dropdown) ChartJS:未捕获的TypeError:无法读取未定义的属性'call' - ChartJS: Uncaught TypeError: Cannot read property 'call' of undefined firebaseui.js未捕获TypeError:无法读取未定义的属性'call' - firebaseui.js Uncaught TypeError: Cannot read property 'call' of undefined 未捕获的TypeError:在Ajax调用后无法读取未定义的属性&#39;appendChild&#39; - Uncaught TypeError: Cannot read property 'appendChild' of undefined after Ajax call 未捕获的类型错误:无法读取 __webpack_require__ 处未定义的属性“调用” - Uncaught TypeError: Cannot read property 'call' of undefined at __webpack_require__ 未捕获的类型错误:无法使用 jQuery 验证读取未定义的属性“调用” - uncaught TypeError: Cannot read property 'call' of undefined using jQuery validation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM