0

I know this has been asked on here in some form but I didn't see any that matched my scenario really. I'm new to Backbone am still trying to get a handle on how to structure my test app.

After reading this I think I addressed the "DOM not ready issue" but maybe not Any thoughts?

John
  • 429
  • 1
  • 3
  • 17

2 Answers2

2

Alternatively, you can set the element as a property like so:

MyApp.AppView = Backbone.View.extend({
    el: $('body'),
    initialize: function() {
    },
    events: {
        "click #clickMe": "doWork"
    },

    doWork: function(evt) {
        evt.preventDefault();
        alert("Work Done!!!!");
    }

});
stephenmuss
  • 2,445
  • 2
  • 20
  • 29
1

If you pass in el on instantiation rather than setting it in the initialization function, it will work as expected.

var mainView = new MyApp.AppView({ el: $("body") });
Skylar Anderson
  • 5,643
  • 1
  • 25
  • 34
  • That does work. However, I was thinking that setting el in the initialize method would take care of having to supply el in the constructor. Any idea why that's not the case in my scenario? – John Apr 13 '12 at 19:03