I am sending an plain old javascript object up with through an action to my route file.
In the route file, I am then fetching a record to update it. The .findRecord()
method returns a resolved promise. However, when inside the .then
my variable declared in the parent scope outside of the then
is an empty object.
routes/task.js
export default Route.extend({
model (params) {
const id = params.task_id
return this.get('store').findRecord('task', id)
},
actions: {
saveNotes (updatedTask) {
// updatedTask is the expected object {name: "New Name}
console.log(`updatedTask outside is:`, updatedTask);
this.get('store').findRecord('task', taskID).then(task => {
// updatedTask is an empty object {}
console.log(`updatedTask inside is:`, updatedTask);
task.setProperties(updatedTask)
task.save()
})
}
}
});
Is this expected behavior?
Aucun commentaire:
Enregistrer un commentaire