来自控制器方法的sails.js 访问控制器方法 [英] sails.js access controller method from controller method

查看:35
本文介绍了来自控制器方法的sails.js 访问控制器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在sail中你不能从另一个控制器中访问其他控制器方法?

How come in sails you cannot access other controller methods from within another one?

像这样.

module.exports = 

   findStore: ->
       # do somthing

   index: ->
      @findStore(); # Error: undefined

编译

module.exports = {
  findStore: function() {},
  index: function() {
    return this.findStore(); // Error: undefined
  }
};

如果你不能这样做,那为什么不呢?我还应该怎么做...

If you can't do this, then why not? how else should I be doing this...

推荐答案

最近几个小时遇到同样的问题.我使用了 api/services 文件夹.它可能不是您真正需要的,但它是一种选择.一个很好的解释是here.哪些服务会添加到 api/sails.js 中的/services 文件夹

Having the same problem for last few hours. I used the api/services folder. It may not be exactly what you need but it is an option. A good explanation is here. What services would one add to the api/services folder in sails.js

这篇关于来自控制器方法的sails.js 访问控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆