gpt4 book ai didi

mongodb - 在 Meteor 应用程序的服务器端使用 Iron Router?

转载 作者:可可西里 更新时间:2023-11-01 10:03:53 26 4
gpt4 key购买 nike

一旦信息被插入数据库,我尝试调用 Router.go('confirmation') 将用户带到确认页面。

Meteor.methods({
'createNewItinerary': function(itinerary){
var userId = Meteor.userId();
ItineraryList.insert({
[....values.....]
},function(){
Router.go('confirmation');
});

}

在服务器控制台中,我得到响应:没有方法 'go' enter image description here

数据插入成功,如何让它路由到确认页面?

-- 编辑--

这行得通吗?好像是但是不知道怎么验证:

Meteor.call('createNewItinerary',itinerary, function(err, data){
if(err){
console.log(err);
}
else Router.go('confirmation');
});

最佳答案

您的建议是不错的选择。您无法在 Meteor 方法中捕获 Router,因为它在服务器端。您必须在回调函数中执行此操作,就像您建议的那样:

Meteor.call('createNewItinerary',itinerary, function(err, data){
if(err){
console.log(err);
}
Router.go('confirmation');
});

要检查服务器上的工作是否正确完成,只需抛出错误,例如:

 throw new Meteor.Error( 500, 'There was an error processing your request' );

然后如果抛出错误,它将被记录在您的客户端。

希望对你有帮助:)

关于mongodb - 在 Meteor 应用程序的服务器端使用 Iron Router?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28913451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com