【发布时间】:2014-01-28 15:06:06
【问题描述】:
我有从sails 命令生成的用户模型和用户控制器。我只想调用我从控制器的模型上创建的函数,例如:
// 用户模型
module.exports = {
attributes: {
name: {
type: 'string',
required: true
}
},
CallUserFunction: function(){
//some code goes here.
}
}
// 用户控制器
module.exports = {
create: function(req, res){
User.CallUserFunction();//can i call function in user Model like this?
}
}
【问题讨论】:
-
如果您的问题是“我可以在我的模型中定义一个类方法吗”,那么答案是“是”。你试过了吗?