javascript - Content is undefined when trying to work with a record in Ember -
i trying update record in ember store. when try this, returns following error:
uncaught error: assertion failed: cannot delegate set('name', test) 'content' property of object proxy : 'content' undefined.
the controller looks this:
import ember 'ember'; export default ember.controller.extend({ model: null, event: { name: "test", id: "adfg8943224xcvsdf" }, actions: { editevent (event) { var event = this.store.find('event', event.id); event.set('name', event.name); event.save() } } });
the route looks this:
import ember 'ember'; export default ember.route.extend(authenticatedroutemixin, { model () { return { event: this.store.find('event') } }, setupcontroller (controller, model) { controller.set('model', model); } });
the template triggers action, sending along object called event, has properties name , id. values of event object come controller , have been set before triggering editevent action:
<form {{action 'editevent' event on="submit"}}>
i believe happening model
hook returning pojo contains promise resolve. if want pass action need do
<form {{action 'editevent' model.event on="submit"}}>
that being said should return promise model
hook ember wait data load before rendering template. way have setup now, if data takes long time load, submit form before model loaded , you'll error.
i think want route (no need override setupcontroller
):
import ember 'ember'; export default ember.route.extend(authenticatedroutemixin, { model () { return this.store.find('event'); } });
then in template:
<form {{action 'editevent' model on="submit"}}>
if need load multiple models should use ember.rsvp.hash
.
see answer: emberjs: how load multiple models on same route?
also, i'm not quite sure action trying don't need find record again. code posted action doesn't anything. gets event , sets event's name own name.
actions: { editevent (event) { // have event, passed in parameter // don't need query store again it. var event = this.store.find('event', event.id); // doesn't sets event.name event.set('name', event.name); event.save() } }
i think mean this:
actions: { editevent (event) { event.set('name', 'updated name'); event.save(); } }
Comments
Post a Comment