![](/img/trans.png)
[英]meteor js (meteor-autoform + iron router) pass value after form is submitted
[英]Issues with dynamic routing using meteor-autoform and iron:router
我正在嘗試做的是創建帶有流星自動格式的表單,該表單將在提交時將用戶重定向到新生成的路由。 我的想法是,我可以將提交的_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});
}
});
然后,我平均可以發布和查找電話。 我的問題是我不確定如何在提交時執行重定向,也不確定如何在新生成的路由上顯示表單結果。
任何幫助,將不勝感激。
我可以通過添加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);}
});
我從這篇文章中獲得了以下信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.