Question

var user = Backbone.Model.extend({
   defaults: {
      timeLeft: 0
   }
});

Backbone model attributes are changed with: user.set('timeLeft', 100)

I need to tween this attribute with greensock. How can i tween a backbone model attribute?

Was it helpful?

Solution

While I personally think that your mixing view logic into your model (that's a nono), you could listen to a change event on your timeLeft attribute.

var User = Backbone.Model.extend({
    defaults: {
        timeLeft: 0
    },
    initialize: {
        this.on("change:timeleft", this.timeLeftChanged);
    },
    timeLeftChanged: function(model, value, options) {
        // your rendering/tween logic
    }
});

Please keep in mind that this is untested and out of the top of my head, so it could be not working. ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top