-
-
Save mstapp/9577835 to your computer and use it in GitHub Desktop.
blog - part 2 attach view to html
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 App = new Backbone.Marionette.Application(); | |
App.addRegions({ | |
primaryRegion: "#primary-region", | |
}); |
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
Module.Controller = Marionette.Controller.extend({ | |
start: function() { | |
// attach view to existing DOM element at '#primary-view' | |
this.view = new Module.View( {el: '#primary-view'} ); | |
// Use attachView(), not show(), to preserve existing pre-rendered content | |
App.primaryRegion.attachView(this.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 isFirstView = true; | |
Module.Controller = Marionette.Controller.extend({ | |
start: function() { | |
if (isFirstView) { | |
isFirstView = false; | |
this.view = new Module.View( {el: '#primary-view'} ); | |
// Use attachView(), not show(), to preserve existing pre-rendered content | |
App.primaryRegion.attachView(this.view); | |
} | |
else { | |
this.view = new Module.View(); | |
App.primaryRegion.show(this.view); | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment