ember.js - Ember js cloning record with relations -
what try achieve: user goes post/3/edit. here form bound model, filled out. , on top
you editing post {{model.title}}
if user changes title changes dynamic. don't want behavior. want apply changes record, if user hit "save" button (and went right on server side).
my idea:
- clone record
- bind cloned record form
- after hit "save" properties of cloned (and edited) record applied original record.
questions
- is right way this?
- is there
record.clone()
, deep copy record with it's relations? - is there way apply changes,
originalrecord.apply(clonedrecord)
?
assuming using ember data:
an easier approach might use setupcontroller
hook in post edit route:
// routes/posts/edit.js export default ember.route.extend({ setupcontroller: function (controller, model) { this._super(controller, model); this.controller.set('statictitle', model.get('title')); } });
then in template:
{{statictitle}}
then when submit form, reset static title new value after successful save:
// controllers/posts/edit.js . . . actions: { savepost: function() { var controller = this; var post = this.get('model'); function onsuccess(savedpost) { controller.set('statictitle', savedpost.get('title'); //transition somewhere } function onfailure() { post.rollback() } post.save().then(onsuccess, onfailure); } }
Comments
Post a Comment