unemployment Posted August 16, 2012 Share Posted August 16, 2012 I have been trying to learn backbone.js, but I can't figure out why my click event isn't firing when I click the home link. What am I missing? Backbone.js var HomeView = Backbone.View.extend({ el: $('.content'), events:{ "click #home": "animateNavigation" }, initialize: function(){ _.bindAll(this, 'displayTrips'); // Add the model collections this.collection = new ModelList(); this.collection.bind('add', this.displayTrips); // Collection event binder }, animateNavigation: function(){ alert('test'); return false; }, displayTrips: function(params){ var items = params.get('data'); //console.log(items); // All the logic for displaying the trips goes here //for(i = 0; i < items.length; i++){ //console.log(items[i]); //} } }); var home_view = new HomeView(); HTML <div class="content"> <div class="left"> <ul> <li> <div class="nav_arrow"></div> <a href="home" class="active" id="home"> <img alt="Home" src="/assets/img/nav/left/star.png"> <span>Home</span> </a> </li> <li> <a href="tropical" id="tropical"> <img alt="Tropical" src="/assets/img/nav/left/fins_grey.png"> <span>Tropical</span> </a> </li> </ul> </div> </div> Link to comment https://forums.phpfreaks.com/topic/267175-backbonejs-click-event-isnt-firing/ Share on other sites More sharing options...
Adam Posted August 16, 2012 Share Posted August 16, 2012 I've not used Backbone before, but looking at the documentation you don't pass in the el property there. Backbone.View.Extend returns a prototype, that you can then construct with the element: var HomeView = Backbone.View.Extend({ ... }); var home_view = new HomeView({el: '...'}); Link to comment https://forums.phpfreaks.com/topic/267175-backbonejs-click-event-isnt-firing/#findComment-1370011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.