为什么res.json()无法正常工作?

时间:2016-11-23 10:06:29

标签: javascript json node.js sails.js

我是 sails.js 的新手,我正在尝试学习如何一起使用模型和控制器。为此我创建了下面给出的代码。现在,当我访问 ...... / corporate_info 时,我在PostMan中看到了JSON格式的所有必填字段。但它似乎并非“来自”我在res.json({})中定义的corporate_info.find()因为响应中没有属性“数据”。它应该是{data:mydata}?

blueprints.js

rest: false

Corporate_infoController

module.exports = {
    operations: function (req, res, next) {
        var params = req.body;
        Corporate_info.find(params, function (err, createdData) {
            if (err) {
                res.badRequest({
                    error: err
                });
            } else {
                return res.json({
                    status: "success",
                    data: createdData
                });
            }
        });

Corporate_info.js (型号)

module.exports = {
  tableName: 'corporate_info',
  autoCreatedAt: false,
  autoUpdatedAt: false,
  attributes: {
    id: {
      type: 'integer',
      required: true,
      autoIncrement: true,
      primaryKey: true,
      size: 11
    },
    fname: {
      type: 'string',
      required: true,
      size: 100
    },
    lname: {
      type: 'string',
      required: true,
      size: 100
    },
    country_code: {
      type: 'string',
      required: true,
      size: 45
    },
    mobile: {
      type: 'string',
      required: true,
      unique: true,
      size: 100
    },
    email: {
      type: 'string',
      required: true,
      size: 100
    },
    address: {
      type: 'string',
      required: true,
      size: 100
    },
    userid: {
      type: 'integer',
      required: false,
      size: 11
    },
    imei_number: {
      type: 'string',
      required: false
    },
    fullname: function(){
      return "Fullname: "+fname+" "+lname;
    }
  }
};

Connections.js

...
 mysqlAdapter: {
    adapter: 'sails-mysql',
    host: 'localhost',
    user: 'root',
      password: '',
    database: 'rockcity_followme'
  }
...

models.js

...
connection: 'mysqlAdapter',
  migrate: 'safe'
...

0 个答案:

没有答案