Skip to content

Instantly share code, notes, and snippets.

@stefri
Created May 28, 2011 15:44
Show Gist options
  • Save stefri/996963 to your computer and use it in GitHub Desktop.
Save stefri/996963 to your computer and use it in GitHub Desktop.
SC.TemplateChangingView
SC.TemplateChangingView = SC.TemplateView.extend(
/** @scope SC.TemplateChangingView.prototype */{
templateNameDidChange: function() {
SC.Logger.debug("Template name was set to " + this.get('templateName'));
this.rerender();
}.observes('templateName'),
/**
Called when the templateName property associated with this <span> 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