【发布时间】:2013-03-19 01:11:34
【问题描述】:
在 batman.js 中调用 after_save 和 before_save 回调方法的正确方法是什么?
我正在寻找类似于 rails 提供的东西。
谢谢
【问题讨论】:
标签: batman.js
在 batman.js 中调用 after_save 和 before_save 回调方法的正确方法是什么?
我正在寻找类似于 rails 提供的东西。
谢谢
【问题讨论】:
标签: batman.js
更新:
查看这篇博文: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
这还没有太多的文档记录,但是您可以看到the tests中描述的完整记录生命周期(步骤、名称、顺序等!)!
【讨论】: