【问题标题】:meteor-autoform cannot display form: Cannot read property 'schema' of undefinedmeteor-autoform 无法显示表单:无法读取未定义的属性“模式”
【发布时间】:2015-10-31 17:14:09
【问题描述】:

我尝试在 Meteor 应用程序中创建类型为 method 的自动表单。

客户端 HTML:

<template name="addLeader">
   <div id="addLeader" class="addLeader">
      <h2></h2>
      {{#autoForm schema=LeaderSchema id="insertPostForm" type="method" meteormethod="serverMethod"}}
      {{> afQuickField name='userName' class='form-input'}}
      {{> afQuickField name='secondName' class='form-input'}}
      {{> afQuickField name='email' class='form-input'}}
      {{> afQuickField name='password' type='password' class='form-input'}}
      <button type="submit" class="btn btn-default full-width accept-button"><span class="glyphicon glyphicon-ok "></span></button>
      {{/autoForm}}
      <button class="btn btn-default full-width cancel-button"><span class="glyphicon glyphicon-remove "></span></button>
   </div>
</template>

客户端JS:

Template.adminPanel.helpers({

    LeaderSchema: function() {
        return Schema.LeaderSchema;
    }
});

lib 中的架构:

Schema = {};

Schema.LeaderSchema = new SimpleSchema({
    userName: {
        type: String,
        label: ""
    },
    secondName: {
        type: String,
        label: ""
    },
    email: {
        type: String,
        label: ""
    },
    password: {
        type: String,
        label: ""
    }
});

服务器方法:

Meteor.methods({
    serverMethod: function(doc) {
        console.log(doc);
    }
});

在我要显示表单的视图中,表单字段未显示,我收到此错误:

Exception in template helper: TypeError: Cannot read property 'schema' of undefined
    at Object.getDefs (http://localhost:3000/packages/aldeed_autoform.js?666ec8103d59fae9aad5553df832ececaa593358:255:18)
    at Object.autoFormGetComponentContext [as getComponentContext] (http://localhost:3000/packages/aldeed_autoform.js?666ec8103d59fae9aad5553df832ececaa593358:516:20)
    at Object.afQuickFieldIsGroup (http://localhost:3000/packages/aldeed_autoform.js?666ec8103d59fae9aad5553df832ececaa593358:7489:30)
    at bindDataContext (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2880:16)
    at Blaze._wrapCatchingExceptions (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:1651:16)
    at http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2928:66
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3476:12)
    at wrapHelper (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2927:27)
    at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:172:18)
    at http://localhost:3000/packages/aldeed_autoform.js?666ec8103d59fae9aad5553df832ececaa593358:7440:22

当我从 html 文件中删除表单字段时,我不会收到错误消息。可能是什么原因?我做错了吗?

我正在使用 autoform docs 进行此操作。

【问题讨论】:

    标签: javascript meteor meteor-autoform


    【解决方案1】:

    您为 LeaderSchema 助手使用了错误的模板。

    这应该可行:

    Template.addLeader.helpers({ // not Template.adminPanel.helpers
        LeaderSchema: function() {
            return Schema.LeaderSchema;
        }
    });
    

    【讨论】:

    • 好的,我有一个主模板和两个嵌套在这个模板中的模板,我还没有看到。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2015-07-10
    • 2018-03-02
    相关资源
    最近更新 更多