【问题标题】:Submit url parameter with form to meteor method将带有表单的 url 参数提交到流星方法
【发布时间】:2015-04-03 01:43:05
【问题描述】:

我使用aldeed:autoform 来渲染表单并通过Meteor.method() 运行其结果。我的表单如下所示:

SelectPlanTemplates = new SimpleSchema({
  templates: {
    type: [String],
    autoform: {
      options: function() {
        return PlanTemplates.find().map(function(doc) {
          return { label: doc.title, value: doc._id };
        });
      },
      noselect: true
    }
  },
  userId: {
    type: String,
    allowedValues: function() {
      return Meteor.users.find().map(function(doc) {
        return doc._id;
      });
    },
    autoform: {
      omit: true
    }
  }
});

在我的模板上,我只是执行以下操作。

+ionContent
  +quickForm(schema="SelectPlanTemplates" id="SelectPlanTemplatesForm" type="method" meteormethod="createPlanFromTemplates")

我的网址的构造类似于/plan/from_templates/{:userId}。我尝试在提交之前创建一个钩子来添加用户 ID。

AutoForm.hooks({
  SelectPlanTemplatesForm: {
    before: {
      method: function(doc) {
        doc.userId = Router.current().params.userId;
        return doc;
      }
    }
  }
});

但是,它似乎永远不会到达这个钩子。

如何获取路由参数并将其与我的表单一起传递给具有自动表单的流星方法?

【问题讨论】:

    标签: javascript meteor meteor-autoform


    【解决方案1】:

    我想我想出了一个有点奇怪的方法。

    在路由器中:

    this.route('selectPlans', {
      waitOn: function() {
        return Meteor.subscribe('plan_templates');
      },
      path: '/select/plan_templates/:_id',
      template: 'selectTemplates',
      data: function() {
        return new selectPlanTemplates({ userId: this.params._id });
      }
    });
    

    然后我将doc=this 添加到我的模板中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-10
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多