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>
Fran83
2
I am interested in you solution. How did you resolve it?
Hi Fran83, welcome to the forums,
This thread was started over a year and a half ago, but received no replies.
So either the OP solved on their own, or has since moved on.
In any case, posting in long dormant threads rarely proves helpful.
Please start a new thread describing the problem you are now having.