use*_*176 8 meteor iron-router meteor-autoform
我正在使用Meteor与AutoForm和铁路由器.
我有一个用于插入数据的autoform,我想重定向到成功插入后添加的数据页面.我该怎么办?
这是For:
{{#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}}
Run Code Online (Sandbox Code Playgroud)
铁路由器:
Router.route('/products/:_id', {
name: 'page',
data: function() { return Products.findOne(this.params._id);}
});
Run Code Online (Sandbox Code Playgroud)
回调/钩
AutoForm.hooks({
add: {
onSuccess: function(doc) {
Router.go('page', ???);
}
}
});
Run Code Online (Sandbox Code Playgroud)
AutoForm挂钩将返回docId.请参阅:https: //github.com/aldeed/meteor-autoform#callbackshooks
this.docId:附加到表单的doc的_id属性(如果有)或者type ='insert'表单,新插入的doc的_id(如果已插入).
所以使用:
Router.go('page',{_id: this.docId});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2122 次 |
| 最近记录: |