Cách sửa lỗi Uncaught TypeError: $template.get is not a function của plugin Visual Composer khi update WordPress lên 4.5

Cập nhật lần cuối 24/05/2016 by trong WordPress vào 24/05/2016 có 1497 Views

Khi chúng ta update WordPress lên bản 4.5 thì plugin Visual Composer (VC) sẽ bị lỗi Uncaught TypeError: $template.get is not a function . Sau đây là cách fix lỗi cho các bạn dev tiếp tục sử dụng VC nhé 😀

Chúng ta sẽ cập nhật lại hàm html2element trong file /wp-content/plugins/js_composer/assets/js/backend/composer-view.js (với phiên bản <4.8) hoặc trong file wp-content/plugins/js_composer/assets/js/dist/backend-actions.min.js (Với phiên bản >4.9)

Chúng ta tìm đến hàm

html2element: function(html) {
 var $template, attributes = {};
 _.isString(html) ? (this.template = _.template(html),
 $template = $(this.template(this.model.toJSON(), vc.templateOptions["default"]).trim())) : (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()
 },

Sau đó thay thế bằng hàm sau:

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()
 },

Lưu lại rồi vào backend F5 đi bạn 😀

Code trong Gist:

Chúc bạn thành công ^^

 

5/5 - (3 votes)
  • Bình luận
Sản phẩm nổi bật của Toản
x