Created
July 17, 2012 15:09
-
-
Save ppcano/3129967 to your computer and use it in GitHub Desktop.
any possible workaround to set ElementId on init method?
This file contains hidden or 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
| 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'), |
This file contains hidden or 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
| 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(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.