未捕获的TypeError:$ template.get不是函数

roy*_*asa 39 javascript wordpress jquery

当我使用名为WpBakery Visual Composer的插件时,我在WordPress中收到此错误.

我正在使用最新版本的WordPress(4.5),使用最新的谷歌Chrome版本,所有插件都会更新.我似乎无法使用Visual Composer添加任何元素或模板.

有人可以帮助我或告诉我可能会发生什么以及如何解决此错误.

我得到的错误:

在此输入图像描述

Ben*_*Ben 101

在这里查看我的答案.

我通过更新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()
    },
Run Code Online (Sandbox Code Playgroud)

/wp-content/plugins/js_composer/assets/js/backend/composer-view.js

或者在wp-content/plugins/js_composer/assets/js/dist/backend.min.js中

希望这对你有用!

  • 这只是让它加载.但是当尝试向页面添加新元素时,问题仍然存在.TypeError:$ template.get(...)未定义 (7认同)
  • 无法读取undefined的属性'属性'是使用上面的代码后出现的错误 (6认同)
  • 不起作用,不能添加元素 (5认同)
  • 哇,我确认它不起作用......似乎有效,但我不能添加新的元素...... (3认同)
  • 为什么我们要改变插件的东西 - 作者不应该解决这个问题吗?当我们再次更新我们在同一个s***...? (2认同)

Ren*_*Mtl 21

@Sorin Haidau

大家好,我正在使用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();
    },
Run Code Online (Sandbox Code Playgroud)

有效的代码:

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()
},
Run Code Online (Sandbox Code Playgroud)

主要区别在于此处(与原始代码相比)

}); this.$el.attr
Run Code Online (Sandbox Code Playgroud)

有一个分号而不是原始的逗号:):

}), this.$el.attr
Run Code Online (Sandbox Code Playgroud)

干杯人:)

更新:这修复了我使用主题astra的20个网站中的19个,其中包含与上述相同的错误...除了一个网站之外的所有网站.

视觉作曲家终于出现后我有这个错误(缺少一半的设计元素)

Uncaught Error: Syntax error, unrecognized expression: .ui-tabs-nav [href=#tab-1415196282-1-8]
Run Code Online (Sandbox Code Playgroud)

我通过更新composer-custom-views.js的第552行来解决这个问题:

$('.ui-tabs-nav [href="#tab-' + params.tab_id + '"]').text(params.title);
Run Code Online (Sandbox Code Playgroud)

而且现在一切都有效.对不起,如果它不适用于所有主题,请尝试使用上面其他人提到的代码.如果这不起作用尝试我的解决方案:)


Elo*_*ito 16

有人在WordPress论坛上发布了这个对我有用的解决方案.

用以下内容替换该html2element功能/wp-content/plugins/js_composer/assets/js/backend/composer-view.js.

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()
        },
Run Code Online (Sandbox Code Playgroud)

编辑:我不得不在不同的情况下第二次进行此替换,并且在我禁用然后重新启用Visual Composer插件 Ultimate Visual Composer 插件之后它才开始工作.

  • 面对使用VC add element pop-up添加新元素时未定义"属性"的问题:/ (2认同)