Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> when I used it I really didn't like that I had to specify the tag name, the class name, etc in a Backbone.View object.

You don't have to do it if you don't want to. Simplest way to not do it is just implement your custom `render`, and you'll have everything in an empty `div` (the default). If you want your template root to be the element's root (el/$el) as well, you can quite trivially do so by calling View#setElement from View#render:

    render: function () {
        return this.setElement($(renderTemplate()));
    }
There you are, stick that in your parent View class and now you don't "have" to specify anything in your view (which, again, you don't have to anyway).

Also, there's no logic in that part, it's just a declarative mapping of your DOM root.

(the caveats of the guy who answered on SO still apply, this will not handle re-rendering as-is and a broken template generating multiple roots will not work correctly)



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: