Created
May 29, 2011 10:20
-
-
Save erichocean/997630 to your computer and use it in GitHub Desktop.
improved SC.TemplateView
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
SC.mixin(SC.TemplateView.prototype, | |
/** @scope SC.TemplateView.prototype */{ | |
templateNameDidChange: function() { | |
SC.Logger.debug("Template name was set to " + this.get('templateName')); | |
this.rerender(); | |
}.observes('template'), | |
/** | |
Called when the template property associated with this view changes. | |
We destroy all registered children, then render the view again and insert | |
it into DOM. | |
*/ | |
rerender: function() { | |
var idx, len, childViews, childView; | |
childViews = this.get('childViews'); | |
len = childViews.get('length'); | |
for (idx = len-1; idx >= 0; idx--) { | |
childView = childViews[idx]; | |
childView.$().remove(); | |
childView.removeFromParent(); | |
childView.destroy(); | |
} | |
var context = this.renderContext(this.get('tagName')); | |
var elem; | |
this.renderToContext(context); | |
elem = context.element(); | |
this.$().replaceWith(elem); | |
this.set('layer', elem); | |
this._notifyDidCreateLayer(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment