Created
July 29, 2014 14:12
-
-
Save alvincrespo/d8ac025b2dc5b69ea4ad to your computer and use it in GitHub Desktop.
Ember Object Dynamic Attributes
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
import Ember from 'ember'; | |
export default Ember.Object.extend({ | |
attrs: {}, | |
attributes: function(){ | |
var attrs = this.get('attrs'); | |
var _this = this; | |
for (var attribute in attrs) { | |
(function(){ | |
var attr = attribute; | |
Ember.defineProperty(_this, attribute, Ember.computed(function(key, value){ | |
if(value) { | |
_this.set('attrs.' + attr, value); | |
return value; | |
} else { | |
return _this.get('attrs.' + attr); | |
} | |
})); | |
}()); | |
} | |
return attrs; | |
}.property('attrs') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment