我正在使用Bookshelf.js。我想听听我的一个模型中的特定属性何时更新。如果是这样,我想运行一个函数。如何收听模型的更新?
答案 0 :(得分:1)
例如:
const User = bookshelf.Model.extend({
tableName: 'users',
initialize() {
this.on('updated', (model) => {
// This is fired after a model is updated
})
}
})
请注意,这不会在您每次使用.set()
更改模型上的属性时触发,而是仅在使用model.save()
将模型保存到数据库时才会触发。