admin管理员组文章数量:1332881
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
1 Answer
Reset to default 7The 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
本文标签:
版权声明:本文标题:javascript - uncaught typeError cannot read property 'attributes' of undefined visual composer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742316061a2451837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论