ember.js - Editing a record in Ember without updating the UI -


i'm using ember , ember-data , i'm trying edit record. problem since inputs two-way-bound model, modifying in form changes model throughout application (even though don't commit changes). hence, changes reflect everywhere in site though aren't stored.

what ember way of editing records without modifying them until user confirms changes? there way clone models?

that's funny, myself ran this, came solution, , documented in own stack overflow question @ calling mymodel.save() returning outdated model. scroll down solution part, second bullet.

my perception pattern, while common, still not well-documented in ember community. example, see these recent discussions:

i solved doing following:

  • hook willtransition event in route that, whenever page doing editing transitioned out of, can execute code right before happens. note covers both clicking way out, or back-button'ing out. if user closes browser, these changes lost anyway, nothing needed handle situation.
  • now in hook, model this.controller.get('model') , @ value of isdirty this.controller.get('model').get('isdirty'). see http://emberjs.com/guides/models/working-with-records/ discussion on how understand isdirty.
  • if isdirty true, call rollback() on model documented @ http://emberjs.com/api/data/classes/ds.model.html#method_rollback.
  • this revert unsaved changes rest of app looks consistent.

i have model orguser has belongsto relationship model orgperson. relationship set { async: true }. rolling orgperson relationship worked me:

ember.route.extend({     actions: {         willtransition: function( transition ) {         this.controller.get('model.orgperson').then( function( value ) {             if ( value.get('isdirty') ) {                 value.rollback();                 }             });         },     } } 

note (a) may not need wrap isdirty call in promise did (e.g. if don't declare { async: true }, , (b) may access value.get('model') if don't have relationship deal with.

note that, in experience, mymodel.rollback() not rollback of relationships! may because i'm using { async: true } every relationship, watch out for.

special @kingpin2k pointing me in right direction on original post.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -