简体   繁体   English

提交表单后,流星js(流星自动表单+铁路由器)传递值

[英]meteor js (meteor-autoform + iron router) pass value after form is submitted

After a form is successfully validated I would like to redirect the user to a specific page and display some values. 成功验证表单后,我想将用户重定向到特定页面并显示一些值。 I don't know if the way I think to use is the correct one. 我不知道我认为使用的方式是否正确。 Here's what I tried already: 这是我已经尝试过的方法:

creating form in template: 在模板中创建表单:

{{> quickForm collection="Transactions" id="insertTransaction" type="insert"}}

then I created the hook to get called when form is validated & inserted 然后我创建了一个钩子,当表单被验证并插入时被调用

AutoForm.addHooks('insertTransaction',{
  onSuccess: function(data){
    Router.go('one', null, {query: 'amount=' + data->amount});
    console.log(data);
  }
});

@Michel Floyd @米歇尔·弗洛伊德(Michel Floyd)

my one.html 我的one.html

<template name="one">
<div class="row">
    <div class="col-sm-7">
       One Page...
    </div>
    <div class="col-sm-5">
        {{ amount }}
    </div>
</div>
</template>

My code from home.js (client/home.js): 我来自home.js(client / home.js)的代码:

AutoForm.addHooks('insertTransaction',{
onSuccess: function(data, data2, data3){

    result = Transactions.findOne(data2, { amount: 1});
    amount = (result["amount"]);
    Router.go('one',{amount: amount});
}
});

Here's my router code: 这是我的路由器代码:

Router.route('/one/:amount',()=>{
name: 'one',
this.render('one', {data: this.params.amount});
});

I get "No route found named "one"" all the time. 我一直得到“找不到名为“一个”的路线”的信息。

First Create a route with amount as a param, ie 首先创建一条以amount为参数的路线,即

Router.route('/one/:amount',()=>{
  name: 'one',
  this.render('one', {data: this.params.amount});
});

Then use Router.go('one',{amount: amount}); 然后使用Router.go('one',{amount: amount});

Note that there's no underscore next to amount in this.params.amount 请注意, this.params.amount amount旁边没有下划线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM