保存(更新)现有模型时未触发验证

Validate Not Triggered When Saving (Updating) Existing Model

本文关键字:验证 模型 更新 保存      更新时间:2023-09-26

我希望帮助理解为什么在保存(即更新)在backbone.js版本1.0.0中的现有模型时不触发验证方法。下面是简化后的伪代码;"新"(模型)位置被验证,但"现有"(模型)位置在保存时不被验证。

if (id) {
 // options contains places collection
 place = this.options.places.get(id);
 place.on('invalid', function(m,e) {...});
 place.save({...}, {wait: true, error: ..., success: ...})
} else {
 place = new App.Place()
 place.on('invalid', function(m,e) {...});
 place.save({...}, {wait: true, error: ..., success: ...})
}

谢谢。

ari

尝试通过传递{ validate: true }:

强制验证
place.save({...}, {wait: true, error: ..., success: ..., validate: true });