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

问题描述

我正在使用 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插入的文档,如果已插入.

所以使用:

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

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

07-17 02:36
查看更多