Meteor autoform 显示一个特定的提交

Meteor autoform display a specific submission

我正在使用 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 );

您需要在您的出版物中添加一个 id 过滤器,其中只有 return 您当前的特定文档。

您的路线代码:

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);
});