How to avoid template wrapping with empty div in Backbone?

前端 未结 6 1999
死守一世寂寞
死守一世寂寞 2020-12-11 15:13

When I create view backbone creates empty div-container if el is not set. Template (this.$el.html(this.template(this.model.toJSON()))) inserted in that div. How

6条回答
  •  春和景丽
    2020-12-11 15:24

    I think the best solution to this is:

    render: function(){
        var html = this.template(this.model.toJSON()));
        var newElement = $(html)
        this.$el.replaceWith(newElement);
        this.setElement(newElement);
        return this;
    }
    

提交回复
热议问题