문제

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?

도움이 되었습니까?

해결책

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. ;-)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top