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

Route to the new data submitted by Meteor autoform using iron router?

我将 Meteor 与 AutoForm 和 Iron Router 结合使用。

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

这是为了:

{{#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);}
});

Callbacks/Hooks

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

AutoForm 挂钩将为您 return 提供 docId。看: https://github.com/aldeed/meteor-autoform#callbackshooks

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

根据 github 上的文档,签名已更改: 不要忘记声明表单或 null 以应用挂钩。

所有表格

AutoForm.addHooks(null,{
    onSuccess: function(formType, result) {
        Router.go('page',{_id: this.docId});
    }
});

具体形式

AutoForm.addHooks(['yourForm'],{
    onSuccess: function(formType, result) {
        Router.go('page',{_id: this.docId});
    }
});

最好检查最新的签名:https://github.com/aldeed/meteor-autoform#callbackshooks

onSuccess: function(formType, result) {
    Router.go(
        ['adminDashboard', result, 'Edit'].join(''), 
        {_id: this.docId}
    );
},