ember.js - Model Property Binding in Ember / Ember-Data -


is there recommended approach or pattern following application flow?

  1. user enters route
  2. model route retrieved , presented user via template.
  3. the template inputs bound model properties user modifies them, data in store updated on fly.
  4. the user navigates away route without hitting "save"

the problem i'm seeing model has retained values changed user, though haven't been persisted backend.

my current approach problem , feels clunky:

in setupcontroller hook, set several default property values model using ember.copy break binding:

setupcontroller: function(controller, model) {     this._super(controller, model);      var goals = model.get('goals');      controller.set('goalone', ember.copy(defaultgoal.get('goalone')));     controller.set('goaltwo', ember.copy(defaultgoal.get('goaltwo')));     controller.set('goalthree', ember.copy(defaultgoal.get('goalthree'))); } 

bind inputs values instead:

{{input value=goalone type='text'}} 

when clicking save, call updatemodel() method sets values model , persists backend.

updatemodel: function() {     var model = this.get('content');     model.set('goalone', this.get('goalone');     model.set('goaltwo', this.get('goaltwo');     model.set('goalthree', this.get('goalthree'); }  actions: {     save: function() {         this.updatemodel();         this.get('content').save();     } } 

check out ember-data-route. lets bind directly models , automatically rolls if users navigate away without saving.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -