使用铁路由器路由到Meteor autoform提交的新数据? [英] Route to the new data submitted by Meteor autoform using iron router?

查看:55
本文介绍了使用铁路由器路由到Meteor autoform提交的新数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Meteor与AutoForm&铁路由器.

I'm using Meteor with AutoForm & Iron Router.

我有一个自动插入数据的表单,我想在成功插入后重定向到我添加的数据页面.我该怎么办?

I have an autoform for inserting a data, and I want to redirect to the page of the data I added after a successful insert. How should I do it?

这是为:

{{#autoForm collection="Products" id="add" type="insert"}}
    <h4 class="ui dividing header">Products Information</h4>
      {{> afQuickField name='name'}}
      {{> afQuickField name='info'}}
    <button type="submit" class="ui button">Insert</button>
{{/autoForm}}

铁路由器:

Router.route('/products/:_id', {
  name: 'page',
  data: function() { return Products.findOne(this.params._id);}
});

回调/挂钩

AutoForm.hooks({
  add: {
    onSuccess: function(doc) {
      Router.go('page', ???);
    }
  }
});

推荐答案

AutoForm挂钩将返回docId.看: https://github.com/aldeed/meteor-autoform#callbackshooks

The AutoForm hook will return you the docId. See: https://github.com/aldeed/meteor-autoform#callbackshooks

this.docId:附加到表单的文档的_id属性(如果有) 有一个,或者对于type ='insert'形式,新的_id 插入的文档(如果已插入).

this.docId: The _id attribute of the doc attached to the form, if there is one, or for an type='insert' form, the _id of the newly inserted doc, if one has been inserted.

因此使用:

Router.go('page',{_id: this.docId});

这篇关于使用铁路由器路由到Meteor autoform提交的新数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆