Last active
November 3, 2015 18:44
-
-
Save syul/20b708d0c5da2db7140c to your computer and use it in GitHub Desktop.
The right way to create view
This file contains 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
var ContentView = BaseView.extend({ | |
tagName:'div', | |
className: 'content', | |
views: { | |
"root": PickView, | |
"heroes": HeroesView | |
}, | |
onInitialize: function (params) { | |
//reference to the current view | |
this.currentView = undefined; | |
BaseView.prototype.onInitialize.call(this, params); | |
Backbone.on("change:page", this.changePage, this); | |
}, | |
changePage: function(viewName){ | |
// safe removing of current view before adding new | |
if(this.currentView) | |
this.currentView.remove(); | |
//var view = new this.views[viewName](); | |
//this.$el.html(view.render().el); | |
// adding the new view | |
this.currentView = new this.views[viewName](); | |
this.$el.html(this.currentView.render().el); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment