Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 查找模板被销毁/重新创建的原因_Javascript_Meteor - Fatal编程技术网

Javascript 查找模板被销毁/重新创建的原因

Javascript 查找模板被销毁/重新创建的原因,javascript,meteor,Javascript,Meteor,试图调试一些东西。在我们的客户端上,我们有一个Accounts.createUser调用,其中包括一个如下所示的回调: function(err) { if (err) { Session.set('entryError', err.reason); } else { return Router.go('/'); } } 使用此设置,正常注册(即无错误)可以正常工作。但是,如果出现错误,模板将被销毁、创建和渲染两次。我发现了,并继续寻找触发这一现象的潜在反应变量

试图调试一些东西。在我们的客户端上,我们有一个Accounts.createUser调用,其中包括一个如下所示的回调:

function(err) {
  if (err) {
    Session.set('entryError', err.reason);
  }
  else {
    return Router.go('/');
  }
}
使用此设置,正常注册(即无错误)可以正常工作。但是,如果出现错误,模板将被销毁、创建和渲染两次。我发现了,并继续寻找触发这一现象的潜在反应变量。我能找到的唯一一件事是两个模板销毁/创建/呈现调用之间的更改是Meteor.logging,包括会话变量。这似乎不是问题的原因,因为当我删除了对它的所有引用和依赖时,问题还在继续

有什么建议吗

预计到达时间:根据以下要求

signUpPage.html:

<template name='signUpPage'>
  <main id="signUpPage">
    <h1 class="accountsTitle">Sign Up</h1>
    <p id="signInPrompt">If you already have an account <a href="/sign-in">sign in</a>.</p>
    <form id='signUpForm'>
      {{> entryError}}
      <div class="form-group">
        <label for="usernameInput">Username</label>
        <input id="usernameInput" type="string" class="form-control" value=''>
      </div>

      <div class="form-group">
        <label for="emailInput">Email Address</label>
        <input id="emailInput" type="email" class="form-control" value=''>
      </div>

      <div class="form-group">
        <label for="passwordInput">Password</label>
        <input id="passwordInput" type="password" class="form-control" value=''>
      </div>

      <div class="form-group">
        <label for="confirmPasswordInput">Confirm Password</label>
        <input id="confirmPasswordInput" type="password" class="form-control" value=''>
      </div>

      <div class="form-group">
        <label for="signupCodeInput">Signup Code</label>
        <input id="signupCodeInput" class="form-control" value=''>
      </div>

      <button type="submit" class="btn btn-primary btn-block">Sign up</button>
    </form>
  </main>
</template>
以下是使用entryError的js文件:

-

-

- 路由器代码由2个文件组合而成:

//--------------------------------------------------------------
// Global Configuration

Router.configure({
  layoutTemplate: 'appBody',
  notFoundTemplate: 'notFoundPage',
  loadingTemplate: 'loadingPage',
  yieldTemplates: {
    'appHeader': {to: 'header'},
    'appFooter': {to: 'footer'}
  }
});

// Have to sign in to access all application pages
Router.onBeforeAction(function() {
  console.log("Global router onBeforeAction calle");
  // if (!Meteor.loggingIn() && !Meteor.user()) {
  if(!Meteor.user()){
    this.redirect('/sign-in');
  }
  this.next();
}, {
  // whitelist which routes you don't need to be signed in for
  except: [
    'signUpRoute',
    'signInRoute',
    'forgotPasswordRoute',
    'signOutRoute',
    'resetPasswordRoute',
    'pageNotFoundRoute'
  ]
});

// Subscriptions application-wide
Router.waitOn(function() {
  if (Meteor.loggingIn() || Meteor.user())
    return Meteor.subscribe("userGroups");
});

//--------------------------------------------------------------
// Root route

Router.route('landingRoute', {
  path: '/',
  onBeforeAction: function(){
    console.log("other global one is being called");
    // if (!Meteor.loggingIn() && !Meteor.user()){
    if(!Meteor.user()){
      this.redirect('/sign-in');
    }else{
      this.redirect('/grove/dashboard');
    }
    this.next();
  }
});


//--------------------------------------------------------------
// Static Routes

Router.route('/glossary', {
  path: '/glossary',
  template: 'glossaryPage'
});

Router.route('/eula', {
  path: '/eula',
  template: 'eulaPage'
});

Router.route('/privacy', {
  path: '/privacy',
  template: 'privacyPage'
});

Router.route('/about', {
  path: '/about',
  template: 'aboutPage'
});

Router.route("signUpRoute", {
  path: "/sign-up",
  template: "signUpPage"
});

Router.route("signInRoute", {
  path: "/sign-in",
  template: "signInPage"
});

Router.route('signOutRoute', {
  path: '/sign-out',
  template: "signOutPage",
  onBeforeAction: function() {
    Meteor.logout();
    Router.go('/');
    this.next();

  }
});

Router.route("forgotPasswordRoute", {
  path: "/forgot-password",
  template: "forgotPasswordPage",
});

Router.route('resetPasswordRoute', {
  path: 'reset-password/:resetToken',
  template: "resetPasswordPage",
  data: function() {
    Session.set('resetToken', this.params.resetToken);
    return ;
  }
});

Router.route("404Route", {
  path: "/page-not-found",
  template: "notFoundPage",
});

Router.route("dashboardRoute", {
  path: "/dashboard",
  template: "dashboardPage"
});

Router.route('createShrub', {
  path: '/tools/createShrub',
  template: 'upsertShrubPage',
  waitOn: function(){
  },
  data: function () {
  },
});

// TODO figure out how to dynamically render templates
// based on if the slug is a group, user, or nothing
// and also conditionally subscribe
Router.route('profileRoute', {
  path: '/:ownerSlug',
  template: 'myProfilePage'
});

Router.route('groveRoute', {
  path: '/:ownerSlug/:groveSlug',
  template: 'grovePage',
  data: function () {
    return Groves.findOne({ slug: this.params.groveSlug });
  },
});

Router.route('shrubRoute', {
  path: '/:ownerSlug/:groveSlug/:shrubSlug',
  template: 'shrubStaticPage',
  data: function() {
    Session.set("currentShrub", this.params.shrubSlug);
    return ShrubTemplates.findOne({ slug: this.params.shrubSlug });
  },
  action: function() {
    if (this.ready())
      this.render();
    else
      this.render('loadingHolder');
  }
});

事实证明,作为路由器的一部分,它具有以下功能:

Router.waitOn(function() {
  if (Meteor.loggingIn() || Meteor.user())
    return Meteor.subscribe("userGroups");
});

Meteor.loggingIn中的更改导致该函数运行,我们在加载页面中看到该函数被短暂显示。我们更改了if语句,使其不再包含Meteor.loggingIn检查。有点尴尬,真的,我发誓我以前看过那句台词。不知道在我的思考过程中发生了什么,错过了这个。至少现在我对Iron Router有了更好的理解。

你能发布相关的模板HTML+JS,以及任何使用entryError会话变量的JS吗?很抱歉要求更多的代码,但是你能发布你的路由/控制器代码吗?我认为这很可能是罪魁祸首。Ta.添加了请求的路由器代码
Template.resetPasswordPage.helpers({
  error: function() {
    return Session.get('entryError');
  }
});

Template.resetPasswordPage.events({
  'submit #resetPasswordForm': function(event, template) {
    event.preventDefault();
    var password = template.find('#passwordInput').value;
    var confirmPassword = template.find('#confirmPasswordInput').value;
    // Validate password
    var passwordErrors = validatePassword(password, confirmPassword);
    if (passwordErrors.length) {
      var errorsString = passwordErrors.join("\r\n");
      return Session.set('entryError', errorsString);
    } else {
      return Accounts.resetPassword(Session.get('resetToken'), password, function(error) {
        if (error) {
          return Session.set('entryError', error.reason || "Unknown error");
        } else {
          Session.set('resetToken', null);
          return Router.go("/");
        }
      });
    }
  }
});


Template.resetPasswordPage.created = function () {
  document.title = "Grove OS | Reset Password";
};
Template.forgotPasswordPage.events({
  'submit #forgotPasswordForm': function(event, template) {
    event.preventDefault();
    var email = template.find("#forgottenEmail").value;
    if (!email.length) {
      return Session.set('entryError', 'Email is required');
    } else {
      return Accounts.forgotPassword({
        email: email
        }, function(error) {
          if (error)
            return Session.set('entryError', error.reason);
          else
            return Router.go("/");
      });
    }
  }
});

Template.forgotPasswordPage.created = function () {
  document.title = "Grove OS | Forgot Password";
};
//--------------------------------------------------------------
// Global Configuration

Router.configure({
  layoutTemplate: 'appBody',
  notFoundTemplate: 'notFoundPage',
  loadingTemplate: 'loadingPage',
  yieldTemplates: {
    'appHeader': {to: 'header'},
    'appFooter': {to: 'footer'}
  }
});

// Have to sign in to access all application pages
Router.onBeforeAction(function() {
  console.log("Global router onBeforeAction calle");
  // if (!Meteor.loggingIn() && !Meteor.user()) {
  if(!Meteor.user()){
    this.redirect('/sign-in');
  }
  this.next();
}, {
  // whitelist which routes you don't need to be signed in for
  except: [
    'signUpRoute',
    'signInRoute',
    'forgotPasswordRoute',
    'signOutRoute',
    'resetPasswordRoute',
    'pageNotFoundRoute'
  ]
});

// Subscriptions application-wide
Router.waitOn(function() {
  if (Meteor.loggingIn() || Meteor.user())
    return Meteor.subscribe("userGroups");
});

//--------------------------------------------------------------
// Root route

Router.route('landingRoute', {
  path: '/',
  onBeforeAction: function(){
    console.log("other global one is being called");
    // if (!Meteor.loggingIn() && !Meteor.user()){
    if(!Meteor.user()){
      this.redirect('/sign-in');
    }else{
      this.redirect('/grove/dashboard');
    }
    this.next();
  }
});


//--------------------------------------------------------------
// Static Routes

Router.route('/glossary', {
  path: '/glossary',
  template: 'glossaryPage'
});

Router.route('/eula', {
  path: '/eula',
  template: 'eulaPage'
});

Router.route('/privacy', {
  path: '/privacy',
  template: 'privacyPage'
});

Router.route('/about', {
  path: '/about',
  template: 'aboutPage'
});

Router.route("signUpRoute", {
  path: "/sign-up",
  template: "signUpPage"
});

Router.route("signInRoute", {
  path: "/sign-in",
  template: "signInPage"
});

Router.route('signOutRoute', {
  path: '/sign-out',
  template: "signOutPage",
  onBeforeAction: function() {
    Meteor.logout();
    Router.go('/');
    this.next();

  }
});

Router.route("forgotPasswordRoute", {
  path: "/forgot-password",
  template: "forgotPasswordPage",
});

Router.route('resetPasswordRoute', {
  path: 'reset-password/:resetToken',
  template: "resetPasswordPage",
  data: function() {
    Session.set('resetToken', this.params.resetToken);
    return ;
  }
});

Router.route("404Route", {
  path: "/page-not-found",
  template: "notFoundPage",
});

Router.route("dashboardRoute", {
  path: "/dashboard",
  template: "dashboardPage"
});

Router.route('createShrub', {
  path: '/tools/createShrub',
  template: 'upsertShrubPage',
  waitOn: function(){
  },
  data: function () {
  },
});

// TODO figure out how to dynamically render templates
// based on if the slug is a group, user, or nothing
// and also conditionally subscribe
Router.route('profileRoute', {
  path: '/:ownerSlug',
  template: 'myProfilePage'
});

Router.route('groveRoute', {
  path: '/:ownerSlug/:groveSlug',
  template: 'grovePage',
  data: function () {
    return Groves.findOne({ slug: this.params.groveSlug });
  },
});

Router.route('shrubRoute', {
  path: '/:ownerSlug/:groveSlug/:shrubSlug',
  template: 'shrubStaticPage',
  data: function() {
    Session.set("currentShrub", this.params.shrubSlug);
    return ShrubTemplates.findOne({ slug: this.params.shrubSlug });
  },
  action: function() {
    if (this.ready())
      this.render();
    else
      this.render('loadingHolder');
  }
});
Router.waitOn(function() {
  if (Meteor.loggingIn() || Meteor.user())
    return Meteor.subscribe("userGroups");
});