我正在使用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 );
答案 0 :(得分:1)
您需要在您的出版物中添加一个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);
});