我使用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.
更多推荐
发布评论