3
这是sails.js中的一个模型。sails.js beforeCreate方法仅接收需要设置为true的模型属性
module.exports = {
attributes: {
name: {
type: "string"
},
email: {
type: "email",
required: true
},
password: {
type: "string"
}
},
beforeCreate: function(values, next) {
console.log(values); //logs {email:"[email protected]"}
console.log(values.email); // logs the email id sent via post
console.log(values.password); // logs undefined is required is set to false, If required is set to true, password will log properly.
next();
}
};
我计划执行的beforeCreate功能密码的一些加密的,当然我会需要密码,可以用它现在继续,但如何公正的情况下需要对此进行管理可选值出现?
你添加了模型与休息API或从控制器?您是否发送所有字段或从您的正面发送电子邮件? – jaumard 2015-04-03 16:03:56
您是否尝试使用beforeValidate方法?要查看它是不同的 – jaumard 2015-04-03 16:04:09
@ jaumard,我正在构建一个没有视图的REST API,此模型绑定到名为/ auth/signup的路由。我正在通过高级休息控制台Chrome应用程序进行POST,是的,我发布了所有字段。 – codin 2015-04-03 16:07:07