当我想从路由器类初始化视图时,我收到此错误.
错误是:未捕获TypeError:对象#没有方法'_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){ } });
路由器:
var blog = new App.Blog(); var blogFormView = App.BlogFormView({model: blog});
drax.. 25
您在路由器代码中缺少新关键字:
var blogFormView = new App.BlogFormView({model: blog});
此外,在initialize方法中调用render通常不是最佳选择.我个人只会在路由器代码中调用render.