Question

I know Backbone.js's View object has parameters like id, tagName, className.

var DocumentRow = Backbone.View.extend({
  tagName: "li",
  className: "document-row",
});

It uses these for the insert template's parent element. When I do not set them, it will add a <div> to the template as the template's parent.

But it really annoys me because sometimes I don't need the parent! All I need I already have in my template, so how can I cancel it?

Was it helpful?

Solution

var DocumentRow = Backbone.View.extend({

  el:'#your-element-id' //or class or type

});

This states that the view is to be bound to a pre-existing element as specified by the el property. Look up the docs at backbonejs.org

Since you already have it in your template just create and bind this view to it "after" the template is created (perhaps in a separate function?)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top