【发布时间】:2012-11-27 01:32:28
【问题描述】:
有没有办法知道猫鼬虚拟设置器何时完成“设置”?
例如:
schema.virtual('file").set(function(fileObj) {
var that = this;
var dst = '/somewhere/else.txt';
fs.rename(fileObj.path, dst, function(err) {
that.set("file.path", dst);
that.markModified('file');
//here i would like to know that the setter finished doing stuff so can potentially save my object
}
});
我面临的问题是,当我设置我的猫鼬模型的file 属性时,我无法知道重命名何时完成,所以当我保存我的对象时,设置器代码有可能没有跑完了。
我知道我可以在模型上创建一个方法来设置文件,但是有没有办法在 setter 中做到这一点?
【问题讨论】: