Reputation: 2461
I'm quite new to ember and trying to write a computed property that checks whether or not a user is online based on their 'state' property, defined in the user model, and then returns a count of the number of users online. This is what I have been attempting, which is not working-
onlineUsers: function() {
return this.get("model").filterBy("state", "online").get("model.length");
}.property("'model.[]'"),
And this is my user model-
App.User = DS.Model.extend({
name : DS.attr('string'),
email : DS.attr('string'),
state : DS.attr('string'),
subjects : DS.hasMany('subject')
});
Can anyone point out what I'm doing wrong?
Upvotes: 0
Views: 628
Reputation: 19128
You need to use [email protected]
onlineUsers: function() {
return this.get("model").filterBy("state", "online").get("length");
}.property("[email protected]"),
Also model.length
in the end not work, because the result of the filterBy
is a new array, and you want the length of that array.
Upvotes: 2