ember.js - Controller not seeing the updated model - asynchronous handling -
i have simple requirement many things in ember.js, i'm banging head against wall trying implemented.
i have overview screen couple of records displayed in table.
to render overview screen i'm using following route
app.locationsindexroute = ember.route.extend({ setupcontroller: function(controller) { var locations = app.location.find(); controller.set('content', locations); }, rendertemplate: function() { this.render('locations.index',{into:'application'}); } });
this working fine. conditionally render overviewtable.
- if records present render table.
- if no records present display message.
i tried implementing using following controller.
app.locationsindexcontroller = ember.arraycontroller.extend({ locationspresent: function() { var model = this.get('content'); return model.content.length > 0; }.property() });
and following template
{{#if locationspresent}} <table class="table table-hover"> <tr> <th>latitude</th> <th>longitude</th> <th>accuracy</th> <th></th> <th></th> </tr> {{#each location in model}} <tr> <td>{{location.latitude}}</td> <td>{{location.longitude}}</td> <td>{{location.accuracy}}</td> <td>{{#linkto locations.edit location}}edit{{/linkto}}</td> <td><button {{action removeitem location}}>delete</button></td> </tr> {{/each}} </table> {{else}} no locations present. {{/if}}
the computed locationspresent
property called once, before page rendered. @ time assume model still being loaded length = 0.
when page rendered, locations app.locations.find() available locationspresent not called anymore, meaning page decided render no locations present.
message.
i went through managing asyncrony in ember page , assumed computer property locationspresent
updated if underlying model changed (if loaded) page states :
using computed property author eliminated need explicitly invoke computation in callback when underlying property changed.
i'd love know i'm doing wrong , how can fix more importantly why seem missing of these core concepts of ember.js. if can point me in docs / guides explained i'd love know.
i think easy fix. need add property observing. so:
locationspresent: function() { var length = this.get('content.length'); return length > 0; }.property('content.@each')
adding @each necessary if locationspresent needs recalculate wen content added. think can observe 'content.isloaded'
Comments
Post a Comment