最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - uncaught typeError cannot read property 'attributes' of undefined visual composer - Stack Overflow

programmeradmin1浏览0评论

I have some visual poser issues. Cant get support due to old versions. Customer wont pay. Issue is that i cant add element in the backend. Error in chrome debug:

I have tried to fix the issue with the code: Uncaught TypeError: Cannot read property 'attributes' of undefined

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

Code:

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

I have checked all over the web and stackoverflow, i cant find the issue for this problem.

I have some visual poser issues. Cant get support due to old versions. Customer wont pay. Issue is that i cant add element in the backend. Error in chrome debug:

I have tried to fix the issue with the code: Uncaught TypeError: Cannot read property 'attributes' of undefined

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

Code:

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

I have checked all over the web and stackoverflow, i cant find the issue for this problem.

Share Improve this question asked Aug 10, 2016 at 12:44 mmmttzzmmmttzz 811 silver badge8 bronze badges 5
  • 1 From error you have problem in this line $template.get(0).attributes. So $template.get(0) return undefined. Make sure you actually have result using get method. Hope this helps. – Mykola Borysyuk Commented Aug 10, 2016 at 12:49
  • Hi Mykola. I get some html code in the console when i log the var $templets.get(0), this means it not undefine correct? Isnt. Attributes old? Shouldnt it be. Attr? – mmmttzz Commented Aug 11, 2016 at 7:52
  • Well.. you have iteration there _.each. Maybe first element is not undefined but some can be.. For example try always console.log $template.get(0) before _.each. also add logs to all variables. And check to see maybe you have extra stuff in $template that you not expecting. Hope this helps. – Mykola Borysyuk Commented Aug 11, 2016 at 9:27
  • If i add: $template = $(template(this.model.toJSON()).trim());console.log($template.get( 0 ).attributes), Output in console: NamedNodeMap {0: data-element_type, 1: class, length: 2} poser-view.js?ver=4.7.4:160 NamedNodeMap {0: data-element_type, 1: data-vc-column-width, 2: class, length: 3} It looks correct. Dont you think ? – mmmttzz Commented Aug 11, 2016 at 10:36
  • 2 i found the solution for this: gist.github./maximspokoiny/34ad60ad90944f8a80c6fc093873a807/… – mmmttzz Commented Aug 12, 2016 at 7:42
Add a ment  | 

1 Answer 1

Reset to default 7

The best solution is replace html2element code & render code in poser view to the following the code

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./maximspokoiny/34ad60ad90944f8a80c6fc093873a807/9fb041d2b12249fe4391f986f4e7e6a08f57c6b3#file-gistfile1-txt

发布评论

评论列表(0)

  1. 暂无评论