Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber View not observing property changes
    primarykey
    data
    text
    <p>I am new to Ember and I am trying to use an Ember View to observe a property change in my controller. I am able to log the view, but the handler doesn't fire when the property changes.</p> <p>I am basically trying to learn the Ember way to remove an item from the view when the user clicks to delete a record. I haven't found really a good guide on this. Any advice is appreciated.</p> <p>Please let me know if I'm leaving anything out. Thanks in advance!</p> <p>(This is an inherited codebase; we aren't ready to upgrade Ember yet.)</p> <blockquote> <p>Ember v1.0.0-rc.3</p> </blockquote> <h3>Route</h3> <pre><code>this.resource('posts'); </code></pre> <pre class="lang-js prettyprint-override"><code>App.PostsRoute = App.AuthenticatedRoute.extend({ // extension of Em.Route model: function() { return App.Post.list(); // returns a list of posts }, events: { // renders a modal in the post context showDeleteModal: function(model) { this.render('modals/_confirmation', { into: 'posts', outlet: 'modal', controller: 'post' }); this.controllerFor('post').set('model', model); } } }); </code></pre> <h3>Controller</h3> <pre class="lang-js prettyprint-override"><code>App.PostsController = Em.ObjectController.extend(App.PagedTable, Ember.Evented, { // ... }); App.PostController = Em.ObjectController.extend({ foo: false, del: function() { this.set('foo', true); } }); </code></pre> <h3>View</h3> <pre class="lang-js prettyprint-override"><code>App.PostsView = Em.View.extend(); App.PostView = Em.View.extend({ didInsertElement: function() { console.log('Inserted!'); }, test: function() { console.log('Observed!'); }.observes('controller.foo') }); </code></pre> <h3>Template</h3> <pre><code>{{#each data in currentDataBlocks itemController="post" itemViewClass="App.PostView"}} &lt;tr&gt; &lt;td&gt;Stuff&lt;/td&gt; &lt;td&gt;Stuff&lt;/td&gt; &lt;td&gt;Stuff&lt;/td&gt; &lt;td&gt;Stuff&lt;/td&gt; &lt;td&gt;&lt;button class="icon-trash" {{action showDeleteModal data}}&gt;&lt;/button&gt;&lt;/td&gt; &lt;/tr&gt; {{/each}} &lt;!-- ... --&gt; {{outlet modal}} </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.
 

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