In Meteor, how do I know on the client-side when the server-side operation is done?

荒凉一梦 提交于 2019-12-31 03:21:06

问题


I know Meteor does client-side caching of the database for better effective performance. In the client-side Meteor method call, is there any way to know when the server-side database operation actually finishes (or if it actually failed)? Are there events I can hook into to get notification when the full remote procedure call finishes? Is there some way to use subscribe() to know when this particular call "really" finishes?

For example, from the simple-todos tutorial, is there a way to get notification when the server-side deleteTask implementation is completely done (i.e. the server-side database has been updated successfully)?

Template.task.events({
  "click .delete": function () {
    Meteor.call("deleteTask", this._id);
  },
});

I know Meteor intentionally hides the server processing delay, but I'm curious about the net operation performance of the Meteor methods I'm writing.


回答1:


Just include a callback with your Meteor.call. The callback will be run after the server has completed processing the request.

Template.task.events({
  'click .delete': function () {
    Meteor.call('deleteTask', this._id, function(err, result){
      if (err){
        // an error was thrown
      } else {
        // everything worked!
      }
    })
  }
});


来源:https://stackoverflow.com/questions/34099162/in-meteor-how-do-i-know-on-the-client-side-when-the-server-side-operation-is-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!