【问题标题】:TypeError: exits.success is not a function [closed]TypeError:exits.success不是一个函数[关闭]
【发布时间】:2019-03-04 12:30:19
【问题描述】:

我正在尝试弄清楚如何将 Sails.js 与 node-machine-syntax 一起使用。这是我的航班列表动作,简单,没有什么疯狂的。 我正在尝试这个:

/**
* FlightsController
*
* @description :: Server-side actions for handling incoming requests.
* @help        :: See https://sailsjs.com/docs/concepts/actions
*/

module.exports = {

 friendlyName: 'flights list',


 description: 'list all flights',

 exits: {
   success: {
     responseType: 'view',
     viewTemplatePath: 'pages/list'
   },
   notFound: {
     description: 'No flight was found in the database.',
     responseType: 'notFound'
   }
 },

 fn: async function (exits) {

   var flights = await Flights.find({});

   // If no flight was found, respond "notFound" (like calling `res.notFound()`)
   if (!flights) { return exits.notFound(); }

   // Display the hompage view.
   return exits.success({flights});
  }
};

但是当我尝试访问页面 /list 时,它会向我显示 500 服务器错误页面,并显示以下消息:“TypeError: exits.success is not a function”。 我真的不明白,因为那是你想要使用的语法.. 它缺少“输入”对象,但我删除了它,因为我真的不需要它,只想在我的数据存储中输出航班。而且它似乎并没有解决问题。

有什么想法吗?谢谢你!

我的飞行模型是这样的:

module.exports = {

 attributes: {
   company:{
     type: 'string',
     required: true
   },
   takeoff:{
     type: 'string',
     required: false
   }
 },

};

我的页面 list.ejs 字面上显示了“LIST”这个词,就像那样。

【问题讨论】:

  • 它已修复。实际上它确实需要一个“输入”对象,即使它是空的。

标签: javascript node.js request sails.js sails-mongo


【解决方案1】:

你还需要把inputs对象,像这样:

/**
* FlightsController
*
* @description :: Server-side actions for handling incoming requests.
* @help        :: See https://sailsjs.com/docs/concepts/actions
*/

module.exports = {

 friendlyName: 'flights list',


 description: 'list all flights',

 inputs: {},

 exits: {
   success: {
     responseType: 'view',
     viewTemplatePath: 'pages/list'
   },
   notFound: {
     description: 'No flight was found in the database.',
     responseType: 'notFound'
   }
 },

 fn: async function (inputs, exits) {

   var flights = await Flights.find({});

   // If no flight was found, respond "notFound" (like calling `res.notFound()`)
   if (!flights) { return exits.notFound(); }

   // Display the hompage view.
   return exits.success({flights});
  }
};

【讨论】:

    猜你喜欢
    • 2020-09-25
    • 2020-06-24
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多