过滤 Ember ArrayProxy

Filtering Ember ArrayProxy

您将如何过滤 ArrayProxy 的结果?我已经尝试过 slice、filter、rejectBy,所有这些都导致视图中没有结果。我想这是因为数据还不可用,但是 then(...) 的使用也没有成功。有什么想法吗?

shownEvents: function(){
    return Em.ArrayProxy.createWithMixins(Em.SortableMixin, {
        content: this.get('shownUser.events'),
        sortProperties: ['eventTime.startTime', 'eventTime.endTime'],
        sortAscending: true
    });
  }.property("shownUser"),

我已经查看了很多与此类似的文章,但没有找到任何有效的文章。

Can I add an additional computed property to an Ember ArrayProxy?

您可以过滤 ArrayProxy,方法是将函数传递给 filter 并返回 true 以获取应通过过滤测试的值。

类似于:

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return { pets: [ { type: 'dog'}, { type: 'cat'}, { type: 'fish'}] };
  }
});

App.IndexController = Ember.ObjectController.extend({
  myPets: function(){
    return Em.ArrayProxy.createWithMixins(Em.SortableMixin, {
      content: this.get('pets'),
      sortProperties: ['type'],
      sortAscending: true
    }).filter(function(item){ return item.type.length === 3});
  }.property("pets"),
});

作品here

如果您已经尝试过,请随意忽略此 ;)