Why are el undefined and $ el defined for this Backbone View?

I am confused by why the `` el '' '' is undefined here, and the value of $ el is determined.

undefined el

Background is an experiment with CoffeeScript as follows:

  class FastTodo.Views.AddTodoItem extends Backbone.View

   template: JST ['todo_items / add_item']

   el: $ ('# main')

   render: ->
     console.log ("render")
     console.log ($ ("# main"))
     console.log (@el)
     console.log (@)
     $ (@ el) .html @template

   initialize: ->
     @render ()

How can I visualize the view in this case?

+4
source share
1 answer

Try rewriting the element declaration in el: '#main'

I think this will work well for you.

By the way, according to your console log, the jQuery ($ el) element is also empty. You must declare a view before the markup is fully loaded. By providing an el selector for elements you make sure that it will be extracted only when the document is ready (loaded).

+5
source

All Articles