Skip to content Skip to sidebar Skip to footer

Backbone View El Not Defined

I have this code - class TableManager tables : {} tableViews :{} nextId : 0 rootEl : 'body' addTable:(json,el)-> newTableModel = new TableModel(json,@nextId)

Solution 1:

You don't have an id="table1" element in the DOM when you instantiate your TableView. For example, if you do this without anything in the DOM:

classVextendsBackbone.View
    el: '#no-such-element'
    render: => console.log @el

v = newV
v.render()

you'll get an undefined in the console.

Demo: http://jsfiddle.net/ambiguous/ne39B/

If you want Backbone to create an id="table1" element then you'll need to use different properties to tell Backbone to do so; the View#el documentation states:

this.el is created from the view's tagName, className, id and attributes properties,

So you have some options:

  1. Make sure #table1 is in the DOM when you create the view.
  2. Pass the el to the view when you instantiate it: v = new TableView(el: some_dom_object).
  3. Use the tagName, className, id, and attributes view attributes to get Backbone to construct the appropriate DOM element for you.

Also, Backbone won't add the view's el to the DOM for you, even if Backbone builds the view's el you'll have to add it to the DOM yourself.

Post a Comment for "Backbone View El Not Defined"