gpt4 book ai didi

javascript - 插件在 WordPress 4.5 更新后抛出 TypeError

转载 作者:IT王子 更新时间:2023-10-29 02:59:53 26 4
gpt4 key购买 nike

我正在调试一个可视化 Composer 插件,该插件在我将 WordPress 更新到 4.5 后出现故障,我无法弄清楚为什么它会抛出 TypeError。

控制台中的错误信息:

JQMIGRATE: Migrate is installed, version 1.4.0              load-scripts.php?....
Uncaught TypeError: $template.get is not a function composer-view.js?ver=4.1.1.1:73

$template 的唯一出现在下面的代码中。我知道这不是很重要的背景,但是我该如何解决这个错误?

/**
* Convert html into correct element
* @param html
*/
html2element: function(html) {
var attributes = {},
$template;
if (_.isString(html)) {
this.template = _.template(html);
$template = $(this.template(this.model.toJSON()).trim());
} else {
this.template = html;
$template = html;
}
_.each($template.get(0).attributes, function(attr) { // **errors on this line**
attributes[attr.name] = attr.value;
});
this.$el.attr(attributes).html($template.html());
this.setContent();
this.renderContent();
},


更新:

看起来这可能是 jQuery 的问题。 WordPress 4.5 包含 jQuery 1.12,它修复了允许某些代码以不正确的语法运行的错误。我假设插件代码一定有不正确的语法,但仍然运行到现在。

https://wordpress.org/support/topic/read-this-first-wordpress-45-master-list#post-8271654

最佳答案

我能够解决这个问题。原来我使用的是旧版本的 JS Composer 。更新到最新版本破坏了我的网站,所以我找到了错误并将 html2element 函数更新为

html2element: function(html) {
var $template, attributes = {},
template = html;
$template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
attributes[attr.name] = attr.value
}), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
},

一切对我来说再次运作良好!希望这对其他人有帮助。

关于javascript - 插件在 WordPress 4.5 更新后抛出 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36605420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com