问题
I am trying to filter a collection based on a related model, I have already tried several ways, but can't get it working:
App.BetroundStatsController = Ember.ArrayController.extend({
needs: "betround",
queryParams: ['query_game'],
sortProperties: ['user.nickName'],
query_game: null,
computeFilter: Ember.computed.filterBy('model','game', this.get('query_game')),
filtered: function(){
return this.get('model').filterProperty('game', this.get('query_game'));
}.property('model.@each.game','query_game'),
filteredBets: function() {
var game = this.get('query_game');
var bets = this.get('model');
if (game) {
return bets.filter(function(item){
return(item.get('game.id') == game);
} );
} else {
return bets;
}
}.property('query_game', 'model'),
newestFilter: function(){
var cont = this;
return this.get('model').filter(function(item, index, self) {
if (item.get('game.id') == cont.get('query_game') ) {
return true;
}
})
}.property('model.@each.game'),
});
来源:https://stackoverflow.com/questions/21512506/filter-with-query-parameter-based-on-related-model