Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here, I've created a ModelProxy mixin so I can have an intermediate proxy object to work with:</p> <pre><code>var defineProperty = Ember.defineProperty; var ModelProxy = Ember.ObjectProxy.extend({ model: Ember.computed.alias('content'), // override this ObjectProxy method to not propagate changes to the model setUnknownProperty: function(key, value) { defineProperty(this, key, null, value); return value; }, // only propagate proxy attributes when the proxy is saved save: function() { var keys = Em.keys(this), content = this.get('content'); keys.forEach(function(key) { content.set(key, self.get(key)); }, this); return content.save(); } }); var ModelProxyMixin = Ember.Mixin.create({ proxy: null, init: function() { this._super(); this.set('proxy', ModelProxy.create({ model: this })); }, }); </code></pre> <p>This is mixed into the Sequence model:</p> <pre><code>var Sequence = DS.Model.extend(ModelProxyMixin, { /*..*/ }); </code></pre> <p>The movies/edit template then uses the proxy when displaying the in-line form fields:</p> <pre><code>{{#each s in sequences itemController='sequence'}} {{#if isEditing}} {{#with s.proxy}} &lt;tr&gt; &lt;td&gt;&lt;button {{action 'save'}}&gt;Save&lt;/td&gt; &lt;td&gt;{{input value=start}}&lt;/td&gt; &lt;/tr&gt; {{/with}} </code></pre> <p>The SequenceController calls #save on the proxy which will then update the original model:</p> <pre><code>actions: { save: function() { this.get('model.proxy').save().then(function() { this.toggleProperty('isEditing'); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload