我已经使用sailsjs生成了api sails生成api testAPI
我可以使用命令
创建数据http://localhost:1337/testAPI/create?username=f1&password=123
我可以得到结果
但是当我想要自定义路线时
获取 - http://localhost:1337/testAPI/1
我正在使用代码
module.exports = {
findOne:function(req,res){
res.ok('overridden');
}
};
在testAPIController.js中进行覆盖
当我走路线http://localhost:1337/testAPI/1
时,我能够看到那里显示的覆盖。
但是如何查询数据并在那里显示自定义视图?
自定义和查询我使用此代码的数据,但它不起作用 说testAPI没有定义
module.exports = {
findOne:function(req,res){
var results = testAPI.find()
res.ok(results);
}
};
所以,我在这里做错了什么?
答案 0 :(得分:0)
您创建的模型应与第一个大写字母一起使用( T \ testAPI.find());
此外,在获取数据时应考虑同步因素。见下面的代码
module.exports = {
findOne:function(req,res){
TestAPI.find().then(function(results) {
return res.ok(results);
});
}
};