我正在使用带有 AutoForm 和 Iron Router 的 Meteor。
我有一个用于插入数据的自动表单,我想在成功插入后重定向到我添加的数据页面。我该怎么做?
这是针对:
{{#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);}
});
回调/ Hook
AutoForm.hooks({
add: {
onSuccess: function(doc) {
Router.go('page', ???);
}
}
});
最佳答案
AutoForm Hook 将返回您的 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});
关于meteor - 使用 Iron Router 路由到 Meteor autoform 提交的新数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29903775/