gpt4 book ai didi

javascript - 如何在不保存在 nodejs 中的情况下仅验证记录 | sails 船 |吃水线

转载 作者:行者123 更新时间:2023-11-29 21:57:14 25 4
gpt4 key购买 nike

我寻求这种性质的东西

//validation rules in model "User"
attributes: {
age: {
required: true,
type: 'numeric'
}
},

//now in controller, i want to be able to do this
Recipe.validate({age: 'An invalid age because it is a string. I except a validation error as response'});

问题是,它不起作用..它提示 beforeValidate 不可用,e.t.c

最佳答案

您需要将回调传递给 .validate:

Recipe.validate({age: 'blah'}, function(err){
if (err && err.invalidAttributes) {
console.log(err.invalidAttributes);
} else {
// model is valid
}
});

关于javascript - 如何在不保存在 nodejs 中的情况下仅验证记录 | sails 船 |吃水线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25824967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com