【发布时间】:2016-08-04 23:07:30
【问题描述】:
我正在调试一个可视化作曲家插件,该插件在我将 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
【问题讨论】:
-
请不要包含错误消息的图像,而是将其作为文本包含。这将有助于未来有类似错误消息的读者通过搜索找到您的问题。
-
到目前为止解决这个问题是否成功?
标签: javascript jquery html wordpress