存在轨道,我们有生命周期挂钩,这让我们这样做:Spine.js,设置模式默认值
class Subscription < ActiveRecord::Base
before_create :record_signup
private
def record_signup
self.signed_up_on = Date.today
end
end
有没有做到同样的事情,最好的方法(我需要它设置一些默认值)在Spine.js
?
目前我这样做,但也许有更好的办法存在?
class Subscription extends Spine.Model
@record_signup: (self) ->
self.signed_up_on = new Date()
Subscription.bind 'beforeSave', Subscription.record_signup
可以进一步简化为:'@bind'beforeSave',@ record_signup'? – Dfr
它完全可以! – Ven