I am looking best practices in Ember.JS to fix the following scenario:
This issue is occurring because all my text field are binded directly to the challenge model and since the model is updated as soon as you type it updates the text on all the routes. I have a cancel button on the edit form where I do this.get('model').rollback() on the model to cancel out the edits. However this gets messy if you start doing rollback in different place on the page you can click.
The way I was thinking about fixing this issue is to have the form field binded to the controller properties and on each route copy the model properties to the controller properties on the setupController hook. This would prevent edits to impact the other routes.
I am wondering if this best practice in ember or is there a better way to fix this issue?
Thank you
You can use single rollback in deactivate
route hook. Then on cancel
action you can do transition only.
// edit challenge route
model(params) {
...
},
deactivate() {
this.modelFor( this.get('routeName')).rollback();
}
PS Are you aware that rollback()
still doesn't work properly with relations and reduced to rollbackAttributes()
in ED 2.0?
Related links: https://github.com/emberjs/data/issues/2122 https://github.com/emberjs/data/issues/3273#issuecomment-110965145
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.