在Meteor中,如何在客户端知道服务器端操作何时完成? [英] In Meteor, how do I know on the client-side when the server-side operation is done?

查看:85
本文介绍了在Meteor中,如何在客户端知道服务器端操作何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Meteor会对数据库进行客户端缓存,以提高性能。在客户端Meteor方法调用中,有没有办法知道服务器端数据库操作实际何时完成(或实际上是否失败)?当完整的远程过程调用完成时,是否有可以挂钩的事件来获取通知?有没有办法使用 subscribe()知道这个特定的电话真的何时结束?

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?

例如,从 simple-todos教程,有没有办法获得通知服务器端deleteTask实现完全完成后(即服务器端数据库已成功更新)?

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);
  },
});

我知道Meteor故意隐藏服务器处理延迟,但我对网络操作性能感到好奇我正在编写的Meteor方法。

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.

推荐答案

只需在 Meteor.call 。服务器完成处理请求后将运行回调。

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!
      }
    })
  }
});

这篇关于在Meteor中,如何在客户端知道服务器端操作何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆