admin管理员组文章数量:1237474
I'm getting this error, when I want to initialize the view from router class.
Error is: Uncaught TypeError: Object # has no method '_ensureElement'
BlogFormView:
App.BlogFormView = Backbone.View.extend({
el: ".data-form",
initialize: function(){
this.template = _.template($("#blog_form_template").html());
this.render();
},
render: function(){
this.$el.html(this.template({blog: this.model.toJSON()}));
return this;
},
events: {
"click .submit-blog" : "submitForm"
},
submitForm: function(ev){
}
});
Router:
var blog = new App.Blog();
var blogFormView = App.BlogFormView({model: blog});
I'm getting this error, when I want to initialize the view from router class.
Error is: Uncaught TypeError: Object # has no method '_ensureElement'
BlogFormView:
App.BlogFormView = Backbone.View.extend({
el: ".data-form",
initialize: function(){
this.template = _.template($("#blog_form_template").html());
this.render();
},
render: function(){
this.$el.html(this.template({blog: this.model.toJSON()}));
return this;
},
events: {
"click .submit-blog" : "submitForm"
},
submitForm: function(ev){
}
});
Router:
var blog = new App.Blog();
var blogFormView = App.BlogFormView({model: blog});
Share
Improve this question
edited Feb 25, 2016 at 18:51
larrydalmeida
1,6303 gold badges17 silver badges31 bronze badges
asked Dec 10, 2013 at 7:17
Emrah AyanogluEmrah Ayanoglu
4662 gold badges6 silver badges16 bronze badges
1 Answer
Reset to default 25You are missing new keyword in router code:
var blogFormView = new App.BlogFormView({model: blog});
Also, it usually isn't best idea to call render inside the initialize method. I personally would just call render inside the router code.
本文标签: javascriptBackbonejs ensureElement errorStack Overflow
版权声明:本文标题:javascript - Backbone.js _ensureElement error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739858318a2200450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论