- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有很多函数,比方说 P()、Q()、R()、S()、T(),我有 3 个 Controller ,A、B 和 C。
Controller A 使用 P() 和 Q(),B 使用 R()、S() 和 T(),而 C 使用 P()、Q() 和 T()。
我已经定义了 Controller ,我应该在哪里定义功能(哪个文件夹)?我如何将它们包含在 Controller 中?
这些功能以后可能会在其他一些 Controller 中使用(并且可以归类)。
最佳答案
在 Sails 1.0 中,您应该使用 Helpers而不是服务。
As of v1.0, all Sails apps come with built-in support for helpers, simple utilities that let you share Node.js code in more than one place. This helps you avoid repeating yourself, and makes development more efficient by reducing bugs and minimizing rewrites. Like actions2, this also makes it much easier to create documentation for your app.
您可以生成一个运行命令的新助手:
sails generate helper get-current-date
将在 helpers
文件夹下创建一个新文件。示例:
module.exports = {
friendlyName: 'Get current date',
description: 'Creates a new Date object and returns it',
inputs: {},
exits: {
success: {
outputFriendlyName: 'Current date',
outputType: 'ref'
},
},
fn: async function (inputs, exits) {
return exits.success(new Date());
}
};
然后像 sails.helpers.getCurrentDate()
一样使用它。
关于node.js - 在 Sails.js 中定义可重用函数的正确位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31668911/
根据文档,sails lift 将始终尝试使用本地安装的 Sails 模块(即 app/node_modules/sails)运行您的应用。 但是当我运行 sails console 时,我可以从堆栈
在我的sails.js我正在尝试关闭服务和模型的默认全局变量,如下所示: sails: true, services: false, models: false 作为一种风格偏好,我想明确使用 sai
我正在用 sails 框架编写一些 api。我有一个 api 需要从两个表中获取数据,所以我想使用这样的 sql 查询: select * from table1 union select * fro
根据 this , 在创建与其他记录关联的新记录时,响应应包含填充的关联记录。 POST /pony { "name": "Pinkie Pie", "pet": 1 } 响应应该是这样的 {
我已经开始从事一个项目,并决定使用 Sails.js 构建 API。我以前没有使用 Sails 的经验,这就是为什么我需要您的推荐。 我需要为许多模型实现行级权限。例如,假设我只想允许对该记录的创建者
我在一个使用 sail.js 的项目中工作,一切正常,但每次我修改某些内容时,我都必须重新启动“sails lift”。是否没有一个选项可以让我在服务器在线时工作并查看我所做的所有更改? 据了解,问题
当sails.js 模块上的电子邮件验证规则失败时,服务器正在崩溃。 这是我的模块的片段: //用户的电子邮件地址 email: { type: 'string', email: true,
我正在尝试在客户端使用 Sails.js 和 sails.io.js 创建一对一聊天。 我可以让 io.socket.get 和 io.socket.post 工作,但是我无法从任何一个 收到任何东西
我刚刚开始使用 Sails.js,它是一个了不起的框架。但是我遇到了一些情况,我找不到谷歌的解决方案,所以我来这里寻求帮助。 我有一个 Controller 连接到另一个远程服务,该服务使用非常旧的
我已经使用 npm install sails -g 成功安装了 sails我运行的是 Windows 7。当我尝试运行“sails”命令时,收到错误消息“找不到命令”。然后我将相应的 bin 文件夹
我正在使用带有船长-s3适配器的船长来处理我的 sails 应用程序中的文件上传。 当文件正常发送时它工作正常,但是当请求中止时我收到未处理的错误消息并且 sails 崩溃。 events.js:85
像 Rails 一样,有什么方法可以向验证器添加自定义错误消息吗? 喜欢: if(this.password != this.passwordConfirmation){ this.errors
我已经使用 npm install sails -g 成功安装了 sails我运行的是 Windows 7。当我尝试运行“sails”命令时,收到错误消息“找不到命令”。然后我将相应的 bin 文件夹
我需要查询关联表(由 sails 创建),所以我不能使用“Model.query”,因为我没有这个表的模型。我找不到解决方案。谢谢 最佳答案 您可以使用其他模型对象,例如 User.query(sql
仅当满足某些条件时,我才需要加密密码。 beforeUpdate: function (value, cb) { User.findOne(value.id) .exec(function (er
在我的风帆应用程序中,我按如下方式编辑 config/models.js 文件以在提升应用程序时清理数据库。 migrate: 'drop', connection: 'mongodb' 但是
我将sails 升级到@^1.0.0 版本,在开发API 时,我想使用Service,但Sails 文档建议现在使用Helper。而且我并没有真正习惯于使用新的方法来识别助手、构建脚本或 Action
我试图弄清楚如何禁用 Sails.js 中模型的自动数据库迁移。 我知道你可以设置migrate: 'safe'在模型中,但是有没有办法为所有模型指定这个? 最佳答案 实际上,有办法做到这一点。 OR
我正在开始一个新项目,我想使用 AngularJS 作为前端,使用 SailsJS 作为后端。我需要为不同的客户分离数据库。因此,每个客户端都必须有自己的数据库。 我没有找到如何在帆和水线中制作这个。
我从 SailsJS 开始和 MySQL ,我的数据库中有很多表。所以,我不知道 SailsJS有一个工具可以从数据库中生成模型,比如 Database First在 Entity Framework
我是一名优秀的程序员,十分优秀!