Reputation: 8318
I'm struggling to understand how promises work in the controller. I'd like to display just the first 10 sortedShips
in my template but I can't find a way to get slice(0,10)
working in my controller.
How can I limit sortedShips
or a new property to the first 10 elements only?
app/controllers/index.js
import Ember from 'ember';
export default Ember.Controller.extend({
shipSort: ['name:asc'],
sortedShips: Ember.computed.sort('model.ships', 'shipSort').property('model.ships')
});
Upvotes: 1
Views: 833
Reputation: 37379
Not sure what split()
is, but Ember's computed.filter function should do the trick:
import Ember from 'ember';
export default Ember.Controller.extend({
shipSort: ['name:asc'],
// You don't need the .property() here, Ember does that for you
sortedShips: Ember.computed.sort('model.ships', 'shipSort'),
firstTenShips: Ember.computed.filter('sortedShips', function(ship, index) {
return (index < 10);
})
});
Upvotes: 3