Jump to content

Backbone.js Click Event Isn't Firing


unemployment

Recommended Posts

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

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: '...'});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.