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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.