【发布时间】:2016-12-04 18:58:24
【问题描述】:
我正在使用meteor autoform和iron:router创建一个表单,在提交时重定向到表单_id(即localhost3000/submit/_id。这一切都很好,但我现在想做的就是让它成为我的模板而已显示形成结果的不是全部。
这是我目前拥有的代码
HTML:
<div class="displayBox">
{{#each Submits}}
{{> formDisplay}}
{{/each}}
</div>
<template name="formDisplay">
<h1>
{{title}}
{{subject}}
{{summary}}
</h1>
</template>
钩子:
AutoForm.addHooks('insertSubmit', {
onSuccess: function(doc) {
Router.go('formDisplay',{_id: this.docId});
}
})
路由:
Router.route('/submit', {
layoutTemplate: 'submitLayout',
waitOn: function() { return Meteor.subscribe("Submits"); },
loadingTemplate: 'loading'
});
Router.route('/submit/:_id', {
name: 'formDisplay',
data: function() { return Products.findOne(this.params._id);},
waitOn: function() { return Meteor.subscribe("Submits"); },
loadingTemplate: 'loading'
});
表格:
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 );
【问题讨论】:
标签: meteor iron-router meteor-autoform