Filter with query parameter based on related model

心已入冬 提交于 2020-01-15 04:49:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!