問題描述
當我使用一個名為 WpBakery Visual Composer 的外掛時,我在 WordPress 中收到此錯誤。
我正在使用最新版本的 WordPress(4.5),使用最新的 Google Chrome 版本和所有外掛更新。我似乎無法使用 Visual Composer 新增任何元素或模板。
有人可以幫我或告訴我可能發生什麼,我可以如何解決這個錯誤。
我得到的錯誤:
最佳解決辦法
請看我的答案 here.
我透過更新 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()
},
在/wp-content/plugins/js_composer/assets/js/backend/composer-view.js
或者在 wp-content /plugins /js_composer /assets /js /dist /backend.min.js
希望這適合你!
次佳解決辦法
@蘇寧海道
嗨,嗨,我正在使用 Astra 主題。這個修復是 99.9%工作。對於某些人來說,這隻會停止旋轉輪,但一旦頁面載入視覺作曲家就不會。
我對這段程式碼做了一個微小的改動 (現在到處都是)
原創 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()
},
主要區別在於這裡 (與原始程式碼相對)
}); this.$el.attr
有一個分號,而不是原來的逗號:):
}), this.$el.attr
乾杯們:)
更新:這固定了 20 個站點中的大約 19 個與主題 astra 有相同的錯誤,如上所述… 除了一個站點之外。
視覺作曲家終於出現 (缺少一半的設計元素) 後,我遇到了這個錯誤
Uncaught Error: Syntax error, unrecognized expression: .ui-tabs-nav [href=#tab-1415196282-1-8]
我透過更新 composer-custom-views.js 的第 552 行來解決這個問題:
$('.ui-tabs-nav [href="#tab-' + params.tab_id + '"]').text(params.title);
而且,所有的東西現在都可以工作。抱歉,如果它不適用於所有主題,請嘗試使用上面提到的程式碼。如果這不行,我的解決方案:)
第三種解決辦法
有人張貼在 WordPress 論壇這個解決方案為我工作。
用/wp-content/plugins/js_composer/assets/js/backend/composer-view.js 替換 html2element 中的 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()
},
編輯:我不得不在不同的情況下再次進行這種替換,並且在停用然後重新啟用 Visual Composer 外掛和 Ultimate Visual Composer add-on 之前,它不會開始工作。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。
