[英]Standard pattern to redirect a submit form after checking the insert was successful, on Meteor with AutoForm & Iron Router?
I'm using Meteor with AutoForm & Iron Router. 我正在使用Meteor与AutoForm和铁路由器。
I have an autoform for inserting a record, and I want to redirect to another page to view the record after a successful insert. 我有一个autoform用于插入记录,我想重定向到另一个页面以在成功插入后查看记录。 What's the generally accepted way to do this?
什么是普遍接受的方式?
If I use the standard autoform insert like: 如果我使用标准的autoform插件,如:
{{#autoForm collection="Articles" id="articleSubmit" type="insert"}}
I can't see how I can redirect? 我看不出如何重定向?
If I use the 'method' type like this: 如果我使用'method'类型,如下所示:
{{#autoForm collection="Articles" id="articleSubmit" type="method"}}
then I have to write an insert method which is not particularly DRY. 然后我必须编写一个不特别干的插入方法。
A form is a form, if you use the type="method"
thats means you are using a Meteor.method
for this, and the form will handle for you, the Meteor.call
表单是一个表单,如果你使用
type="method"
这意味着你正在使用Meteor.method
,表格将为你处理, Meteor.call
Now if you want to do some Router.go()
, you will need to write some JS code, you can use the hooks, wich come with the autoform package, like this for example 现在如果你想做一些
Router.go()
,你需要编写一些JS代码,你可以使用钩子,它带有autoform包,就像这样的例子
Articles.hooks({
contactForm: {
onSubmit: function (insertDoc, updateDoc, currentDoc) {
if (someHandler(insertDoc)) {
this.done();
Articles.clean(doc); / you can do more logic here, cleaning the form.
Router.go('thePath');
} else {
this.done(new Error("Submission failed"));
}
return false;
}
}
});
So you don't need a common 'submit #articleSubmit'
use the auto forms API better. 所以你不需要一个常见的
'submit #articleSubmit'
更好地使用auto forms API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.