Created
July 6, 2016 13:58
-
-
Save jmimi/f2421a7b73ec5b252a706a306bfde4a7 to your computer and use it in GitHub Desktop.
How to update nested object in Ember
This file contains 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.Controller.extend({ | |
appName: 'Ember Twiddle', | |
critService: Ember.inject.service(), | |
init(){ | |
this._super(...arguments); | |
this.get('critService').loadCrits(); | |
}, | |
actions: { | |
modifyCrit(crit) { | |
crit.set('value',1000); | |
} | |
} | |
}); |
This file contains 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'; | |
const KeyVal = Ember.Object.extend({ | |
key: null, | |
value: null | |
}); | |
export default Ember.Service.extend({ | |
crits: null, | |
loadCrits() { | |
var newCrits = Ember.A(); | |
var max = Math.random() * 10; | |
for(var i=0; i<max; i++) { | |
var crit = Ember.A(); | |
var num = Math.random() * 5; | |
for(var j=0; j<num; j++) { | |
let item = KeyVal.create({key: "data"+j, value: j}); | |
crit.pushObject(item); | |
} | |
let newItem = KeyVal.create({key: "crit"+i, value: crit}); | |
newCrits.pushObject(newItem); | |
} | |
this.set("crits", newCrits); | |
} | |
}); |
This file contains 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
{ | |
"version": "0.10.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.6.0", | |
"ember-data": "2.6.1", | |
"ember-template-compiler": "2.6.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment