0

batman.js中调用after_save和回调方法的正确方法是什么?before_save我正在寻找类似于 rails 提供的东西。

谢谢

4

1 回答 1

0

更新:

查看这篇博文:http ://rmosolgo.github.io/blog/2014/03/19/batman-dot-model-lifecycle-callbacks/

希望能帮助到你!


我只是自己调查了一下。我发现获得此功能的一个好方法是在构建后立即将侦听器记录在案,从而利用模型的生命周期:

class App.Thing extends Batman.Model
   constructor: ->
     super # instantiates the record

     @get('lifecycle').onEnter 'save', =>
       console.log('about to save!')

     @get('lifecycle').onExit 'save', =>
       console.log('just saved!')

     @ # return the record

这还没有太多文档记录,但是您可以看到测试中描述的完整记录生命周期(步骤、名称、顺序等!) !

于 2013-10-26T16:41:16.313 回答