【问题标题】:Issues with dynamic routing using meteor-autoform and iron:router使用meteor-autoform和iron:router的动态路由问题
【发布时间】:2016-12-04 17:54:54
【问题描述】:

我想要做的是创建一个带有流星自动表单的表单,它将用户重定向到提交时新生成的路由。我的想法是,我可以将提交的 _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});
  }
});

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

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript meteor iron-router meteor-autoform


    【解决方案1】:

    我可以通过添加一个 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);}
    });
    

    我从这篇文章中得到了这个信息:

    Route to the new data submitted by Meteor autoform using iron router?

    【讨论】:

      猜你喜欢
      • 2015-02-12
      • 2017-12-03
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多