Skip to content

Instantly share code, notes, and snippets.

@ppcano
Created July 17, 2012 15:09
Show Gist options
  • Select an option

  • Save ppcano/3129967 to your computer and use it in GitHub Desktop.

Select an option

Save ppcano/3129967 to your computer and use it in GitHub Desktop.
any possible workaround to set ElementId on init method?
elementId: Ember.computed(function(key, value) {
return value !== undefined ? value : Ember.guidFor(this);
}).cacheable(),
_elementIdDidChange: Ember.beforeObserver(function() {
throw "Changing a view's elementId after creation is not allowed.";
}, 'elementId'),
Em.View.extend({
init: function() {
var elementId = Ember.meta(this).proto['constructor'].superclass.toString();
elementId = elementId.toString().replace('App.','');
elementId = elementId.toString().replace('View','');
elementId = Ember.String.underscore(elementId);
this.set('elementId', elementId);
this.set('templateName', elementId );
this._super();
}
});
@donovan-graham

Copy link
Copy Markdown

Em.View.extend({

_generateId: function() {
var elementId = Ember.meta(this).proto['constructor'].superclass.toString();
elementId = elementId.toString().replace('App.','');
elementId = elementId.toString().replace('View','');
elementId = Ember.String.underscore(elementId);
this.set('elementId', elementId);
// this.set('templateName', elementId );

}.on('init')

});

Should do the trick. Note elementId's can't be changed after init as ember uses them to manage the views and keeps an internal track of id's in Ember.View.views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment