Reputation: 1331
I want to use my template & view to edit a single record. Server returns an array that may or may not be populated. Controller is ObjectController, and I currently populate it by findAll(1). How can I use findAll() and return first item in returned array or an empty object?
Thanks
Upvotes: 0
Views: 43
Reputation: 10552
What I would do is have an ArrayController
to hold the results of the findAll
call, and then bind to that as such:
App.RecordsController = Ember.ArrayController.extend();
App.RecordController = Ember.ObjectController.extend({
needs: 'records',
contentBinding: 'controllers.records.firstObject'
});
In your route you can do:
setupController: function () {
this.controllerFor('records').set('content', Blah.findAll());
}
Upvotes: 1