Meteor AutoForm:带id的表单;asdf”;需要“;模式“;或“;集合“;属性

Meteor AutoForm: form with id "asdf" needs either "schema" or "collection" attribute

本文关键字:需要 模式 属性 集合 asdf id Meteor 表单 AutoForm      更新时间:2023-09-26

我有一个想要使用模式渲染的自动表单。我在template.name.helpers({:

Template.name.helpers({
  getSchema: function() {
    var schema = new SimpleSchema({
      location: {
        type: String,
        label: "Start location"
      }
    });
    return schema;
  }

html:

{{#autoForm schema=getSchema id="submitOfferLift" type="method"}}

然而,我无法让助手工作(相关文档)。此外,如果我只是在template.js中定义schema = {...},并在autoform中指定schema = "schema",我会收到一条消息,说schema没有在窗口范围中定义。此外,如果我在控制台中创建模式变量,则表单呈现得很好。

您的助手正在返回一个简单对象,而它本应返回一个SimpleSchema实例

Template.name.helpers({
  getSchema: function() {
    var schema = new SimpleSchema({
      location: {
        type: String,
        label: "Start location"
      })
      return schema;
  }
})

此外,模板包含应使用>而不是#

{{> autoForm schema=getSchema id="submitOfferLift" type="method"}}