Created
August 8, 2012 18:00
-
-
Save scottcorgan/3297104 to your computer and use it in GitHub Desktop.
HomeView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I encourage you to attach all these views to a global object named 'App' | |
/* | |
// You should put this in the index.html file towards the top | |
window.App = {}; | |
*/ | |
// This is better because then it's now attached to the global namespace | |
// Calling Backbone.View.extend is equivalent to defining a class | |
// Look below, for a comment on instantiation | |
window.HomeView = Backbone.View.extend({ | |
el: '#content', | |
initialize:function () { | |
console.log('Initializing Home View'); | |
}, | |
render:function () { | |
// You were calling the this.template() function, and it did not exist | |
// You need to call in your template files with a script loader ($.getScript or requirejs) | |
// then render them. | |
// | |
// Google "underscore.js templates" | |
// | |
// | |
// Also, this.$el is a build in attribute to backbone.js which | |
// is equivalent to $(this.el) | |
// | |
this.$el.html('<div id="calendar"></div>'); | |
// Return the jQuery object of the element | |
// This makes sense because you are calling render() function | |
// Although, this is not necessary, it makes it so you can | |
// chain function calles such as homeView.render().hide().fadeIn(), etc... | |
return this.$el; | |
} | |
}); | |
// You need to instantiate the view | |
// Just like Java :) | |
var homeView = new HomeView; | |
// Calling the render function, because Backbone doesn't | |
// automatically call it. | |
homeView.render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment