繁体   English   中英

使用meteor-autoform和iron:router进行动态路由的问题

[英]Issues with dynamic routing using meteor-autoform and iron:router

我正在尝试做的是创建带有流星自动格式的表单,该表单将在提交时将用户重定向到新生成的路由。 我的想法是,我可以将提交的_id用作iron:router参数。 到目前为止,我所看到的如下:

表格创建

Submits = new Meteor.Collection('Submits');

Submits.allow({
  insert: function(username, doc){
    return !!username;
  }
});

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

路由

Router.route('/submit', {
  layoutTemplate: 'submitLayout',
  waitOn: function() { return Meteor.subscribe("Submits"); },
  loadingTemplate: 'loading'
});

Router.route('/submit/:_id', {
  name: 'formDisplay',
  data: function() {
    return Submits.findOne({this.params._id});
  }
});

然后,我平均可以发布和查找电话。 我的问题是我不确定如何在提交时执行重定向,也不确定如何在新生成的路由上显示表单结果。

任何帮助,将不胜感激。

我可以通过添加autoform.hook并稍微更改路由来做到这一点。

自动成型挂钩:

AutoForm.addHooks('insertSubmit', {
  onSuccess: function(doc) {
    Router.go('formDisplay',{_id: this.docId});
  }
})

路由:

Router.route('/submit/:_id', {
  name: 'submitLayout',
  data: function() { return Products.findOne(this.params._id);}
});

我从这篇文章中获得了以下信息:

使用铁路由器路由到Meteor autoform提交的新数据?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM