在使用AutoForm和铁路由器的Meteor上检查插入成功后重定向提交表单的标准模式?(Standard pattern to redirect a submit form after checki

编程入门 行业动态 更新时间:2024-10-10 07:23:31
在使用AutoForm和铁路由器的Meteor上检查插入成功后重定向提交表单的标准模式?(Standard pattern to redirect a submit form after checking the insert was successful, on Meteor with AutoForm & Iron Router?)

我使用AutoForm和Iron Router的流星。

我有一个autoform插入一条记录,我想重定向到另一个页面,以成功插入后查看记录。 什么是普遍接受的方式来做到这一点?

如果我使用标准autoform插入,如:

{{#autoForm collection="Articles" id="articleSubmit" type="insert"}}

我看不到我如何重定向?

如果我使用'method'类型,如下所示:

{{#autoForm collection="Articles" id="articleSubmit" type="method"}}

那么我必须写一个不特别干的插入方法。

I'm using Meteor with AutoForm & Iron Router.

I have an autoform for inserting a record, and I want to redirect to another page to view the record after a successful insert. What's the generally accepted way to do this?

If I use the standard autoform insert like:

{{#autoForm collection="Articles" id="articleSubmit" type="insert"}}

I can't see how I can redirect?

If I use the 'method' type like this:

{{#autoForm collection="Articles" id="articleSubmit" type="method"}}

then I have to write an insert method which is not particularly DRY.

最满意答案

一个表单是一个表单,如果你使用type="method" ,那就意味着你正在使用Meteor.method来完成这个工作,表单会为你处理, Meteor.call

现在如果你想做一些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; } } });

所以你不需要一个普通的'submit #articleSubmit'更好地使用自动窗体API。

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

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

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.

更多推荐

本文发布于:2023-07-29 03:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1311970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   重定向   铁路   模式   标准

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!