uncaught typeError无法读取属性'属性'未定义的视觉作曲家

时间:2016-08-10 12:44:48

标签: javascript jquery json ajax wordpress

我有一些视觉作曲家的问题。 由于旧版本无法获得支持。客户不会付钱。 问题是我无法在后端添加元素。 chrome调试出错:

我试图用代码解决问题: 未捕获的TypeError:无法读取属性'属性'未定义的

<pre>
html2element    @   composer-view.js?ver=4.7.4:156
render          @   composer-view.js?ver=4.7.4:163
addShortcode    @   composer-view.js?ver=4.7.4:232
addShortcode    @   composer-view.js?ver=4.7.4:561
_               @   load-scripts.php?c=0&load[]=thickbox,hoverIntent,common,admin-bar,word-count,suggest,wp-ajax-respon…:474
m               @   load-scripts.php?c=0&load[]=thickbox,hoverIntent,common,admin-bar,word-count,suggest,wp-ajax-respon…:474
f               @   load-scripts.php?c=0&load[]=thickbox,hoverIntent,common,admin-bar,word-count,suggest,wp-ajax-respon…:474
l.trigger       @   load-scripts.php?c=0&load[]=thickbox,hoverIntent,common,admin-bar,word-count,suggest,wp-ajax-respon…:474
ListenerHelper.triggerShortcodeEvents   @   events.js?ver=4.7.4:19
(anonymous function)    @   composer-view.js?ver=4.7.4:977
and alot fo load script errors
</pre>

代码:

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

我已经检查了整个网络和stackoverflow,我无法找到这个问题的问题。

1 个答案:

答案 0 :(得分:6)

最好的解决方案是替换html2element代码&amp;在composer视图中将代码呈现给以下代码

html2element: function(html) {
            var attributes = {},
                $template;
            if (_.isString(html)) {
                this.template = _.template(html);
                $template = $(this.template(this.model.toJSON(), vc.templateOptions.default).trim());
            } else {
                this.template = html;
                                $template = $(this.template(this.model.toJSON(), vc.templateOptions.default).trim());
            }

            _.each($template.get(0).attributes, function(attr) {
                attributes[attr.name] = attr.value;
            });
            this.$el.attr(attributes).html($template.html());
            this.setContent();
            this.renderContent();

        },
        render: function() {
            var $shortcode_template_el = $('#vc_shortcode-template-' + this.model.get('shortcode'));
            if ($shortcode_template_el.is('script')) {
                this.html2element(_.template($shortcode_template_el.html()));
            } else {
                var params = this.model.get('params');
                $.ajax({
                    type: 'POST',
                    url: window.ajaxurl,
                    data: {
                        action: 'wpb_get_element_backend_html',
                        data_element: this.model.get('shortcode'),
                        data_width: _.isUndefined(params.width) ? '1/1' : params.width,
                        _vcnonce: window.vcAdminNonce
                    },
                    dataType: 'html',
                    context: this
                }).done(function(html) {
                    this.html2element(html);
                });
            }
            this.model.view = this;
            this.$controls_buttons = this.$el.find('.vc_controls > :first');
            return this;
        },

Soruce:https://gist.github.com/maximspokoiny/34ad60ad90944f8a80c6fc093873a807/9fb041d2b12249fe4391f986f4e7e6a08f57c6b3#file-gistfile1-txt