Created
March 27, 2014 13:41
-
-
Save rafi/9807808 to your computer and use it in GitHub Desktop.
Rough draft for dynamic regions and views loading into layout (Backbone.js, Marionette.js, RequireJS)
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 _this = this, | |
pendingViewPaths = []; | |
options = options || {}; | |
this.layout = this.getFormLayout(options); | |
this.elements = options.collection; | |
this.show(this.layout); | |
this.elements.each(function (element) { | |
var elementName = element.get('id'), | |
regionName = elementName+'Region', | |
regionElName = elementName+'-region'; | |
pendingViewPaths.push('components/form/element/'+element.get('formatter')); | |
_this.layout.addRegion(regionName, '#'+regionElName); | |
_this.layout.$el.append('<div id="'+regionElName+'"></div>'); | |
}); | |
require(pendingViewPaths, function() { | |
_.each(pendingViewPaths, function (path, index) { | |
var view = require(path), | |
element = _this.elements.at(index), | |
regionName = element.get('id')+'Region'; | |
_this.layout[regionName].show(new view({ model: element })); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment