Sails.js Sails JS,如何将请求参数映射到模型?

Sails.js Sails JS,如何将请求参数映射到模型?,sails.js,sails.io.js,Sails.js,Sails.io.js,我想将request.params中的json数据映射到控制器类中的模型。 在将模型保存到数据库之前,它在控制器中有一些操作 它有没有解决方案可以自动将json数据映射到模型对象,而无需手动执行此操作 var email=req.body.email; var phone=req.body.phone 如果我正确理解了你的问题,那么我会的 我经常会构建这样的表单: <input type="text" name="data[email]" value="ex@example.com">

我想将request.params中的json数据映射到控制器类中的模型。 在将模型保存到数据库之前,它在控制器中有一些操作

它有没有解决方案可以自动将json数据映射到模型对象,而无需手动执行此操作

var email=req.body.email;
var phone=req.body.phone

如果我正确理解了你的问题,那么我会的

我经常会构建这样的表单:

<input type="text" name="data[email]" value="ex@example.com">
<input type="text" name="data[phone]" value="1234567890">
更新数据库时:

User.create(data).exec(funtion(e,r){
    console.log(e||r)
    // if there is no error, object r should contain:
    // {
        id : <id>, 
        email : 'ex@example.com', 
        phone : '1234567890', 
        createdAt : <date>, 
        updatedAt : <date>
       }
})
User.create(data).exec(函数(e,r){
控制台日志(e | | r)
//如果没有错误,对象r应包含:
// {
id:,
电邮:'ex@example.com', 
电话:1234567890,
createdAt:,
更新日期:
}
})

谢谢你,梅祖达。这是我需要的解决方案,我的荣幸!快乐编码)
User.create(data).exec(funtion(e,r){
    console.log(e||r)
    // if there is no error, object r should contain:
    // {
        id : <id>, 
        email : 'ex@example.com', 
        phone : '1234567890', 
        createdAt : <date>, 
        updatedAt : <date>
       }
})