Backbone.js _ensureElement错误

 手机用户2502863461 发布于 2023-02-11 19:01

当我想从路由器类初始化视图时,我收到此错误.

错误是:未捕获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.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有