【问题标题】:meteor js (meteor-autoform + iron router) pass value after form is submitted流星 js (meteor-autoform + iron router) 表单提交后传值
【发布时间】:2017-05-21 18:07:41
【问题描述】:

成功验证表单后,我想将用户重定向到特定页面并显示一些值。我不知道我认为使用的方式是否正确。这是我已经尝试过的:

在模板中创建表单:

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

然后我创建了在验证和插入表单时调用的钩子

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

@米歇尔·弗洛伊德

我的.html

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

我的 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});
}
});

这是我的路由器代码:

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

我总是收到“找不到名为“one”的路线”。

【问题讨论】:

  • 这个想法在我看来是合理的。
  • 似乎使用data-&gt;amount 不起作用。当我只使用数据作为 GET 参数 data 传递时,我只得到“插入”。如何访问值本身?
  • 那不是data.amount吗?但我不使用 IronRouter,所以我不太清楚那条线上发生了什么。我只是说整体想法似乎合理。

标签: javascript meteor iron-router meteor-autoform


【解决方案1】:

首先创建一个以amount为参数的路由,即

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

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

注意this.params.amountamount旁边没有下划线

【讨论】:

  • 如何创建路由?我将我的代码发布到第一篇文章中。
  • 这太奇怪了,请查看我在第一篇文章中的更新。就是这么奇怪。现在它没有找到模板。
  • 您是否也有正在使用的布局模板?通常,单个路由会在布局模板内呈现为 {{&gt; yield}}
猜你喜欢
  • 2015-07-06
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 2014-06-03
  • 2015-11-08
  • 1970-01-01
  • 2016-03-23
  • 2015-09-15
相关资源
最近更新 更多