我正在使用meteor autoform和iron:router创建一个表单,该表单在提交时重定向到表单提交(即localhost3000/ _id /_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 );发布于 2016-07-30 19:23:17
您需要在您的出版物中添加一个id过滤器,它只返回当前特定的文档。
您的路线代码:
Router.route('/submit/:_id', {
name: 'formDisplay',
data: function() { return Products.findOne(this.params._id);},
waitOn: function() { return Meteor.subscribe("Submits", { '_id': this.params._id } ); },
loadingTemplate: 'loading'
});您的发布代码:
Meteor.publish('tasks', function(filter) {
filter = ( filter ? filter : {} );
return Products.findOne(filter);
});https://stackoverflow.com/questions/38669313
复制相似问题