I have made a little demo app where I have a tweet list and I am changing the number of favorites for a random tweet every 0.3 seconds, and the list is supposed to show the top 3 tweets based on favorites, but I can't get it to resort every time a number of favorites is changed for a tweet.
I have made a demo in jsfiddle with this application(show list has to be pressed to show the list).
In my sorting function I want it to check if favorites has changed for any of tweets
App.AppModel = Ember.Object.extend({
topTweets: function(){
return this.get('tweets').toArray().sort(function(a, b){
console.log("sort");
return b.favorites-a.favorites;
}).slice(0, 3);
}.property('tweets.@each.favorites')
});
This is where I change a random tweets favorites
setInterval(function(){
var iPosition = _.random(0, numTweets-1);
var iFavorites = _.random(0, 4000);
App.appModel.get('tweets').set(iPosition+'.favorites', iFavorites);
App.appModel.get('tweets').set(iPosition+'.text', iFavorites)
}.bind(this),300);
The favorites are changing I'm just wondering why isn't the list resorting.
Aucun commentaire:
Enregistrer un commentaire