簡體   English   中英

meteor-autoform無法顯示表單:無法讀取未定義的屬性“schema”

[英]meteor-autoform cannot display form: Cannot read property 'schema' of undefined

我嘗試在Meteor應用程序中使用type method創建autoform。

客戶端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做的。

您使用了錯誤的LeaderSchema助手模板。

這應該工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM