Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Last active Dec 20, 2015
Embed
What would you like to do?
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