Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Last active December 20, 2015 18:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianjmiller/6174702 to your computer and use it in GitHub Desktop.
Save brianjmiller/6174702 to your computer and use it in GitHub Desktop.
Example of changing view through attach/detach
_changeView: function (newView, options) {
console.log("app::_changeView");
options = options || {};
options.renderFirst = (typeof options.renderFirst !== "undefined") ? options.renderFirst : true;
if (this._currentView !== null && this._currentView === newView) {
console.log("app::_changeView - no change needed");
return;
}
if (this._currentView !== null) {
this._currentView.$el.detach();
}
this._currentView = newView;
if (options.renderFirst) {
this._currentView.render();
}
this._containerNode.append(this._currentView.$el);
}
handleContent: function (page) {
console.log("app::handleContent - page: " + page);
var view = this._views[page],
ViewCtr;
if (typeof view === "undefined") {
ViewCtr = this.contentViewConstructors[page];
view = this._views[page] = new ViewCtr ();
}
this._changeView(view);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment