Meteor: Meteor.call() from within observe callback does not execute

前端 未结 2 1251
萌比男神i
萌比男神i 2021-01-06 04:11

Is there any possibility of calling a server method from within a observe callback in Meteor?

I put together an example that reproduces the issue, that

2条回答
  •  伪装坚强ぢ
    2021-01-06 04:31

    This might be a known issue, i'm not sure since I've not tried it myself, but it looks like there might be a workaround (see https://github.com/meteor/meteor/issues/907)

    Add your Meteor.call into an instantaneous setTimeout callback:

    added: function(doc) {
        console.log("added "+doc.text);
        setTimeout(function() {
            Meteor.call('aMethod',doc.text,function(e,r){
                if(e){
                    console.log("error from server: "+e);
                }else{
                    console.log("response from server: "+r);
                }
            });
        },0);
    }
    

提交回复
热议问题