我正在尝试做的是创建一个带有meteor-autoform的表单,它将在提交时将用户重定向到新生成的路由。我的想法是,我可以将提交的_id用作iron:router参数。到目前为止,我拥有的内容如下所示:
形式的创造
Submits = new Meteor.Collection('Submits');
Submits.allow({
insert: function(username, doc){
return !!username;
}
});
SubmitSchema = new SimpleSchema({
title: {
type: String,
label: "Title"
},
subject:{
type: String,
label: "Subject"
},
summary:{
type: String,
label: "Summary"
},
author:{
type: String,
label: "Author",
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Created At",
autoValue: function(){
return new Date()
},
autoform: {
type: "hidden"
}
}
});
Submits.attachSchema( SubmitSchema );路由
Router.route('/submit', {
layoutTemplate: 'submitLayout',
waitOn: function() { return Meteor.subscribe("Submits"); },
loadingTemplate: 'loading'
});
Router.route('/submit/:_id', {
name: 'formDisplay',
data: function() {
return Submits.findOne({this.params._id});
}
});然后我只有平均的发布和查找调用。我的问题是,我不确定如何在提交时执行重定向,也不确定如何在新生成的路由上显示表单结果。
任何帮助都将不胜感激。
发布于 2016-07-30 08:26:55
我可以通过添加一个autoform.hook并稍微更改一下路由来做到这一点。
自动形成挂钩:
AutoForm.addHooks('insertSubmit', {
onSuccess: function(doc) {
Router.go('formDisplay',{_id: this.docId});
}
})路由:
Router.route('/submit/:_id', {
name: 'submitLayout',
data: function() { return Products.findOne(this.params._id);}
});我从这篇文章中获得了以下信息:
Route to the new data submitted by Meteor autoform using iron router?
https://stackoverflow.com/questions/38668566
复制相似问题