0
我有一个相当典型的需求,以确保在我运行查找之前插入/更新已完成。该代码是这样的:如何在运行查找之前确保流星中的更新已完成?
//Update my collections
Messages.insert({author:_id,text:text});
Authors.update({_id:_id},{$inc:{messages:1}});
//Wait until the update/insert has finished
//Perform some actions on the collections just updated
var author = Authors.findOne({task:taskId},{sort:{'messages':1}});
//Do some more complex stuff...
虽然在大多数情况下,这将是罚款,异步调用,与DOM更新到什么时候的事情完成后,在我的情况下,它是必不可少的插入和更新之前已经完成我运行函数调用。
是否需要使用回调函数执行插入和更新作为服务器端调用,或者有什么方法可以在客户端执行此操作?
目前我有类似:
Meteor.call("recordMessage", _id, text,
function(err, out){postMessage(_id)}
);
其作品 - 但我想知道如果我能做到这一点在客户端。
我不知道这个答案在相关的流星问题[延迟从更新反应流星模板] [1]可能有帮助吗? [1]:http://stackoverflow.com/questions/17118812/how-can-i-delay-a-reactive-meteor-template-from-updating-an-html-template-variab – tonemcd