javascript - 如何仅验证记录而不保存在 Node js 中?风 sails js |吃水线

标签 javascript node.js sails.js waterline sails-mongo

我寻求这种性质的东西

//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 不可用,等等

最佳答案

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

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

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

相关文章:

javascript - Node.js "Error: Can not find module"

node.js - Sails.js/Waterline - 创建不是模型上的函数

ajax - 检测 Ajax 并在 SailsJs 中设置布局为空

javascript - 使用 javascript 中的单个映射检查同构字符串

javascript - 工厂没有被注入(inject) Controller - angularJS

javascript - 从 'initialize' 中的函数引用 Prototype.js 函数

node.js - 将 ES6 Generator 函数与 SailsJS 结合使用

javascript - 如何仅运行此 Angular $interval 函数三次(3 个循环)

javascript - 如何在 Express 中向 req.url 添加查询字符串?

javascript - `npm build` 没有在 package.json 中构建 't run the script named "