使用铁路由器路由到Meteor autoform提交的新数据?

使用铁路由器路由到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});