我正在调试一个视觉作曲家插件,在我将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作曲家.更新到最新版本会破坏我的网站,因此我追踪错误并将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()
},
一切都很适合我!希望这有助于其他人.
原文地址:https://codeday.me/bug/20190928/1826712.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。