Skip to content

Instantly share code, notes, and snippets.

@alvincrespo
Created July 29, 2014 14:12
Show Gist options
  • Save alvincrespo/d8ac025b2dc5b69ea4ad to your computer and use it in GitHub Desktop.
Save alvincrespo/d8ac025b2dc5b69ea4ad to your computer and use it in GitHub Desktop.
Ember Object Dynamic Attributes
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