【发布时间】:2014-04-20 22:44:19
【问题描述】:
我了解 Meteor 方法允许您进行客户端到服务器调用,但是从 Meteor 方法调用另一个函数或方法的最佳方法是什么,即服务器到服务器调用。
现在,如果我执行常规 JS 函数调用,它仅在 JS 文件位于 lib 文件夹中时才有效。但我需要它在服务器文件夹中。
这里是代码
我有一个主题集合,它位于集合文件夹中,具有以下内容
我有以下这是一个集合
Meteor.methods({
topicPost: function(topicAttributes) {
var user = Meteor.user(),
topicWithSameTitle = Topics.findOne({title: topicAttributes.title});
// ensure the user is logged in
if (!user)
throw new Meteor.Error(401, "You need to login to add a new topic");
Meteor.call('checkUser');
}
});
然后我有以下方法,它位于服务器文件夹中
Meteor.methods({
checkUser: function () {
alert('aaaa');
}
});
【问题讨论】:
-
这似乎不正确。见stackoverflow.com/a/10156935/223225。你能发布你的代码吗?
-
没关系,它的工作原理没有不知道的方法,也许我昨晚深夜工作时犯了语法错误
标签: meteor