0

I have the following Ember.js code (in a model):

subdata: DS.hasMany('App.Subdata'),
message_subdata: function() {
    return this.get('subdata').filterBy('tag', 'message');
}.property('subdata', 'subdata.@each')

This worked just fine in RC7. In RC8+, I know they made changes to the way that observers fire, but for the life of me, I can't figure out how to get it working again. I know it says to make sure to call get before observing the property, but I'm using this property in a template, so doesn't the template have to get the property?

Right now, when the page first loads, none of the data gets shown because none of the subdata is loaded yet. That's how it's always been. But in RC7, as soon as the records were loaded, it would fire the observers and update the page. Now, for some reason, the observers aren't being update and the page won't update. The only way I can seem to force it to update is by changing the subdata property (or simulating a change with notifyPropertyChange).

How can I get my properties to work as they did in RC7?

EDIT: I thought I would give a quick update on how I did sorting AND filtering. It's probably not the best way, but I fiddled for a while to land on this solution.

subdata: DS.hasMany('App.Subdata'),
message_subdata_filtered: Ember.computed.filterBy('subdata', 'tag', 'message'),
message_subdata: Ember.computed.sort('message_subdata_filtered', function(a,b) {
    return a.get('timestamp') - b.get('timestamp');
});

There might be a way to do it in one line, but this works for me.

4

1 回答 1

1

我猜计算数组的新方法是使用这样的东西:

subdata: DS.hasMany('App.Subdata'),
message_subdata: Ember.computed.filterBy('subdata', 'tag', 'message')
于 2013-09-02T22:54:19.457 回答