【发布时间】: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