我试图弄清楚如何将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不是函数”。 我真的不明白,因为那是您要使用的语法。 它缺少“输入”对象,但是因为我并不是真的需要它,而只是想在我的数据存储中输出广告投放,所以我删除了它。而且它似乎也无法解决问题。
有什么想法吗?谢谢!
我的飞行模型如下所示:
module.exports = {
attributes: {
company:{
type: 'string',
required: true
},
takeoff:{
type: 'string',
required: false
}
},
};
我的页面list.ejs确实显示了单词“ LIST”,就像这样。
答案 0 :(得分: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});
}
};