Skip to content

Instantly share code, notes, and snippets.

@denisovlev
Created April 3, 2015 20:09
Show Gist options
  • Save denisovlev/645e0df163e6c7ff46e4 to your computer and use it in GitHub Desktop.
Save denisovlev/645e0df163e6c7ff46e4 to your computer and use it in GitHub Desktop.
App = Ember.Application.create();
App.Router.map(function() {
// put your routes here
});
App.HashType = Ember.ArrayProxy.extend({
willDestroy: function() {
this.get('content').forEach(function(valueObject) {
valueObject.destroy();
});
}
});
App.HashType.reopenClass({
createRecord: function(hash) {
fieldsArray = [];
model = App.HashType.create({content: fieldsArray});
Ember.keys(hash).forEach(function(key, index) {
value = hash[key];
valueObject = Ember.Object.create({
key: key,
value: value
});
fieldsArray.pushObject(valueObject);
Ember.defineProperty(model, key, Ember.computed.alias('content.'+index+'.value'));
});
return model;
}
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return App.HashType.createRecord({
red: '#f00',
green: '#0f0',
blue: '#00f'
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment