【问题标题】:Meteor autoform display a specific submissionMeteor autoform 显示一个特定的提交
【发布时间】: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


    【解决方案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);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-08
      • 2015-09-15
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      相关资源
      最近更新 更多