繁体   English   中英

流星AutoForm:ID为“ asdf”的表单需要“ schema”或“ collection”属性

[英]Meteor AutoForm: form with id “asdf” needs either “schema” or “collection” attribute

我有一个要使用模式呈现的自动表单。 我在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 = {...} ,并在自动表单中指定schema = "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"}}

暂无
暂无

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

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