我的一个环回模型的结构如下:
{ "name":{ "first":"sam", "last":"billings" } }
是否可以“要求”验证“第一”和“最后”属性?我知道可以通过给出“required”来验证第一级属性:true,但是如何验证嵌套属性?任何帮助,将不胜感激 . 提前致谢!
你可以自定义验证,如:
Model.validateAsync('name', customValidator, {message: 'Name is not correct'}); function customValidator(err, done){ process.nextTick(() => { if (!this.name || !this.name.first || !this.name.last) err(); done(); }); } };
1 回答
你可以自定义验证,如: