流星autoform显示具体提交
问题描述:
我使用流星autoform和铁路:路由器创建一个窗体,重定向到形式_id提交(即localhost3000 /提交/ _id。这一切都很好,但我现在想做的是使它所以我的模板只显示形式的结果不是所有的人流星autoform显示具体提交
这里是我目前有
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);
答
您需要添加一个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);
});
谢谢你这么多的作品完美! – Blezx