• <legend id='8rc6W'><style id='8rc6W'><dir id='8rc6W'><q id='8rc6W'></q></dir></style></legend>

    <small id='8rc6W'></small><noframes id='8rc6W'>

      1. <tfoot id='8rc6W'></tfoot>
        • <bdo id='8rc6W'></bdo><ul id='8rc6W'></ul>
      2. <i id='8rc6W'><tr id='8rc6W'><dt id='8rc6W'><q id='8rc6W'><span id='8rc6W'><b id='8rc6W'><form id='8rc6W'><ins id='8rc6W'></ins><ul id='8rc6W'></ul><sub id='8rc6W'></sub></form><legend id='8rc6W'></legend><bdo id='8rc6W'><pre id='8rc6W'><center id='8rc6W'></center></pre></bdo></b><th id='8rc6W'></th></span></q></dt></tr></i><div id='8rc6W'><tfoot id='8rc6W'></tfoot><dl id='8rc6W'><fieldset id='8rc6W'></fieldset></dl></div>

        如何让 onBeforeAction 调用等到内部的函数调用在meteor.js中完成?

        How to make onBeforeAction call wait until a function call inside finishes in meteor.js?(如何让 onBeforeAction 调用等到内部的函数调用在meteor.js中完成?)
          <bdo id='LAxZ7'></bdo><ul id='LAxZ7'></ul>

            <legend id='LAxZ7'><style id='LAxZ7'><dir id='LAxZ7'><q id='LAxZ7'></q></dir></style></legend>
          • <i id='LAxZ7'><tr id='LAxZ7'><dt id='LAxZ7'><q id='LAxZ7'><span id='LAxZ7'><b id='LAxZ7'><form id='LAxZ7'><ins id='LAxZ7'></ins><ul id='LAxZ7'></ul><sub id='LAxZ7'></sub></form><legend id='LAxZ7'></legend><bdo id='LAxZ7'><pre id='LAxZ7'><center id='LAxZ7'></center></pre></bdo></b><th id='LAxZ7'></th></span></q></dt></tr></i><div id='LAxZ7'><tfoot id='LAxZ7'></tfoot><dl id='LAxZ7'><fieldset id='LAxZ7'></fieldset></dl></div>
                <tbody id='LAxZ7'></tbody>
                1. <small id='LAxZ7'></small><noframes id='LAxZ7'>

                  <tfoot id='LAxZ7'></tfoot>
                  本文介绍了如何让 onBeforeAction 调用等到内部的函数调用在meteor.js中完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个与 meteor.js 同步的 onBeforeAction 方法

                  I have a synchronized onBeforeAction method with meteor.js

                  Router.onBeforeAction(function() {
                      var self;
                  
                      self = this;
                  
                      authToken = Session.get('authToken');
                  
                     if (!authToken) {
                         this.redirect('login');
                         this.next();
                     } else {
                         Meteor.call('validateAuthToken', authToken, function (error, result)) {
                             if (result) {
                                 self.next();
                             } else {
                                 self.redirect('login');
                                 self.next();
                             }
                         }
                     }
                  });
                  

                  我需要通过调用服务器调用来验证存储在 Session 中的身份验证令牌.但是这个方法在我执行的时候总是会抛出异常.我发现原因是因为 onBeforeAction 调用在 validateAuthToken 调用返回之前终止.因此 self.next() 不会采取行动.所以我想知道我该怎么做才能防止 onBeforeAction 调用停止,直到 validateAuthToken 返回验证结果然后继续?

                  I need to validate an authentication token stored in Session by invoking a server call. But this method always throws an exception when I am executing it. And I found out the reason is because the onBeforeAction call is terminated before the validateAuthToken call returns. And thus the self.next() won't take action. So I wonder what can I do to prevent the onBeforeAction call from stopping until the validateAuthToken returns the validated result and then proceed?

                  我通过等待会话变量尝试了不同的实现,但似乎就绪状态从未设置为 true

                  I've tried a different implementation by wait on a session variable, but it seems the ready state is never set to true

                  Router.onBeforeAction(function() {
                      var authToken;
                  
                      authToken = Session.get('authToken');
                  
                      if (!authToken) {
                          this.redirect('login');
                          this.next();
                      } else {
                          Meteor.call('validateAuthToken', authToken, function (error, result) {
                              if (!error) {
                                  Session.set("tokenValidated", result);
                              }
                          });
                  
                          this.wait(Meteor.subscribe('token', Session.get('tokenValidated')));
                          if (this.ready()) {
                              if (!Session.get("tokenValidated")) {
                                  this.redirect('login');
                                  this.next();
                              } else {
                                  this.next();
                              }
                          }
                      }
                  
                  });
                  

                  推荐答案

                  您也可以使用 https://github.com/iron-meteor/iron-router/issues/426

                  Ready = new Blaze.ReactiveVar(false);
                  Router.route('feed',{
                    waitOn: function () {
                      Meteor.call('getInstagramUserFeed', function(error, result) {
                        if(!error) Ready.set(result)
                      });
                      return [
                        function () { return Ready.get(); }
                      ];
                    },
                    action: function () {
                      if (this.ready()) this.render('feed')
                      else this.render('LoadingMany');
                    }
                  });
                  

                  这篇关于如何让 onBeforeAction 调用等到内部的函数调用在meteor.js中完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)

                    <small id='p8o8T'></small><noframes id='p8o8T'>

                  • <tfoot id='p8o8T'></tfoot>
                    • <bdo id='p8o8T'></bdo><ul id='p8o8T'></ul>
                        <i id='p8o8T'><tr id='p8o8T'><dt id='p8o8T'><q id='p8o8T'><span id='p8o8T'><b id='p8o8T'><form id='p8o8T'><ins id='p8o8T'></ins><ul id='p8o8T'></ul><sub id='p8o8T'></sub></form><legend id='p8o8T'></legend><bdo id='p8o8T'><pre id='p8o8T'><center id='p8o8T'></center></pre></bdo></b><th id='p8o8T'></th></span></q></dt></tr></i><div id='p8o8T'><tfoot id='p8o8T'></tfoot><dl id='p8o8T'><fieldset id='p8o8T'></fieldset></dl></div>

                            <tbody id='p8o8T'></tbody>

                            <legend id='p8o8T'><style id='p8o8T'><dir id='p8o8T'><q id='p8o8T'></q></dir></style></legend>