【问题标题】:How to navigate to new page when click on submit button using `meteor js`使用`meteor js`单击提交按钮时如何导航到新页面
【发布时间】:2014-01-31 08:45:17
【问题描述】:

点击提交或登录按钮时,我需要如何使用 meteor js导航到具有相同窗口的新页面。请帮我怎么写。 当用户提交表单页面时,导航到 admindetails.html 页面。我正在使用路由器包,html 页面和客户端代码如下。我的意图是在用户 login同一窗口中动态加载另一个模板 之后。请帮助我。

Here is html page 

<template name="body">
  <div class="bgbody">
     <div align="center">
    <form id="login-form" action="/admindetails">
        <table>
        <p class="admin">Admin Login</p>
        <tr>
           <td><p for="username">Admin Name</p></td>
           <td><input type="text"  id="username" name="username"  placeholder="UserName"></td>
        </tr>
        <tr>
               <td><p for="password">Password</p></td>
           <td><input type="password" id="pwd" name="password"  placeholder="password"></td>
        </tr>
            <td></td><td><input class="btn btn-success" type="submit" value="Log In"></td>
        </table>
    </form>
     </div>
  </div>
</template>

这是客户端代码

if (Meteor.isClient) 
{
 Meteor.Router.add({

    '/admindetails':'admindetails'

    })
  Template.body.events
  ({
    'submit #login-form' : function (e,t)
 {
      /* template data, if any, is available in 'this'*/
      if (typeof console !== 'undefined')

        console.log("You pressed the button");
         e.preventDefault();
  /*retrieve the input field values*/
         var email = t.find('#username').value
         , password = t.find('#pwd').value;
           console.log(email);
   Meteor.loginWithPassword(email, password, function (err)
    {
    if (err) 
    {
      console.log(err);
      alert(err.reason);
      Session.set("loginError", true);
     }
     else
     {
       console.log(" Login Success ");
    Meteor.Router.to("/admindetails");
     }
    });
    }
  });
}

【问题讨论】:

    标签: meteor router


    【解决方案1】:

    如果您使用推荐的Iron Router,则使用go 方法:

    Router.go('/articles/example');
    

    或:

    Router.go('showArticle', {name: 'example'});
    

    如果您使用旧的Router,请使用:

    Meteor.Router.to('/articles/example');
    

    如果您不使用任何路由器,请立即开始。同时,使用石器时代的方法:

    window.location.href = '...';
    

    【讨论】:

    • 它正在工作,但视图没有修改我也在发送我的代码@Hubert OG
    猜你喜欢
    • 1970-01-01
    • 2015-03-16
    • 2023-03-28
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    相关资源
    最近更新 更多