导语:有一位客户使用了Astra主题,在打开页面可视化设置的时候,总是卡在加载的环节,我看了一下是js报错了,错误为:Uncaught TypeError: $template.get is not a function。
问题描述
打开文章或页面的时候,可视化工具一直在旋转,加载不出来内容。鼠标右键查看,发现是composer-view.js报错了。
Uncaught TypeError: $template.get is not a function
问题修复
下面为原始的Astra主题的composer-view.js代码:
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) {
attributes[attr.name] = attr.value;
});
this.$el.attr(attributes).html($template.html());
this.setContent();
this.renderContent();
},
更改为:
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()
},
这样可以修复大部分使用Astra主题的网站出现可视化加载错误的问题。
你可以参考这里的文档:http://stackoverflow.com/questions/36641618/uncaught-typeerror-template-get-is-not-a-function
结束
你学会了吗?顺便说一句,Astra主题搭建企业站很好用。



