2016-08-30 8 views
0

ここで間違っていますかわからないので、ご援助ください。テンプレートヘルパーで例外が発生しました:TypeError:未定義の 'schema'プロパティを読み取れません

以下のエラーをご覧ください。あなたは、コレクションに添付したら素早く形にスキーマを渡す必要はありません

////This is the client side JS//// 
 

 
if (Meteor.isClient) { 
 
Template.NewPerson.helpers({ 
 
    PersonSchema: function(){ 
 
    return schema.PersonSchema; 
 
    } 
 
}); 
 
} 
 

 
////This is the schema//// 
 

 
Person = new Mongo.Collection('person'); 
 

 
Person.allow({ 
 
\t insert: function(userID, doc){ 
 
\t \t return !!userID; 
 
\t } 
 
}); 
 

 
const PersonSchema = new SimpleSchema({ 
 
\t FirstName: { 
 
\t \t type: String, 
 
\t \t label: "First Name" 
 
\t }, 
 
\t LastName: { 
 
\t \t type: String, 
 
\t \t label: "Last Name" \t 
 
\t }, 
 
\t IdentityNumber: { 
 
\t \t type: Number, 
 
\t \t label: "Identity Number" 
 
\t }, 
 
\t Address: { 
 
\t \t type: String, 
 
\t \t label: "Address" 
 
\t }, 
 
\t PhoneNumber: { 
 
\t \t type: Number, 
 
\t \t label: "Phone Number" 
 
\t }, 
 
\t User: { 
 
\t \t type: String, 
 
\t \t label: "User", 
 
\t \t autoValue: function(){ 
 
     return this.userId; 
 
     }, 
 
     autoform: { 
 
      type: "hidden", 
 
      label: false, 
 
\t \t }, 
 
\t \t 
 
\t \t }, 
 
\t 
 
\t //createdAt: { 
 
\t // \t type: Date, 
 
\t // \t label: "Created At", 
 
\t // \t autoValue: function(){ 
 
\t \t \t 
 
\t // \t } 
 
\t // \t autoForm: { 
 
\t // \t \t type: "hidden" 
 
\t //}, 
 
\t 
 
}); 
 

 
Person.attachSchema(PersonSchema); 
 
Error: 
 
Exception in template helper: TypeError: Cannot read property 'schema' of undefined
////This is the error//// 
 

 
Exception in template helper: TypeError: Cannot read property 'schema' of undefined 
 
    at Object.quickFormContext (http://localhost:3000/packages/aldeed_autoform.js?hash=5dbf44ff89f182bd8c2512330e170ef4d5bf9582:6713:34) 
 
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2994:16 
 
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1653:16 
 
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3046:66 
 
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3687:12) 
 
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3045:27 
 
    at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=65db8b6a8e3fca189b416de702967b1cb83d57d5:172:18) 
 
    at http://localhost:3000/packages/aldeed_autoform.js?hash=5dbf44ff89f182bd8c2512330e170ef4d5bf9582:6662:23 
 
    at wrappedArgFunc (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2903:14) 
 
    at .<anonymous> (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2616:26) 
 
debug.js:41 Exception in defer callback: TypeError: Cannot read property 'id' of null 
 
    at .<anonymous> (http://localhost:3000/packages/aldeed_autoform.js?hash=5dbf44ff89f182bd8c2512330e170ef4d5bf9582:6551:22) 
 
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1875:20 
 
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3687:12) 
 
    at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1873:29 
 
    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2214:12) 
 
    at viewAutorun (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1872:18) 
 
    at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?hash=f525263111eb9d90f4ce1ad064f97aca4a6c1b07:339:36) 
 
    at new Tracker.Computation (http://localhost:3000/packages/tracker.js?hash=f525263111eb9d90f4ce1ad064f97aca4a6c1b07:229:10) 
 
    at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?hash=f525263111eb9d90f4ce1ad064f97aca4a6c1b07:604:11) 
 
    at Blaze.View.autorun (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1885:22)
////This is the client side HTML//// 
 

 
<template name="NewPerson"> 
 
    <div class="new-person-container"> 
 
    \t {{> quickForm collection=Person id="insertPersonForm" type="insert" class="new-person-form"}} 
 
    \t </div> 
 
</template>

+0

さらに詳しく問題を説明してください。 – n1c9

答えて

0
Person = new Mongo.Collection('person'); 

Person.allow({ 
    insert: function(userID, doc){ 
     return !!userID; 
    } 
}); 

Person.attachSchema(new SimpleSchema({ 
    FirstName: { 
     type: String, 
     label: "First Name" 
    }, 
    LastName: { 
     type: String, 
     label: "Last Name" 
    }, 
    IdentityNumber: { 
     type: Number, 
     label: "Identity Number" 
    }, 
    Address: { 
     type: String, 
     label: "Address" 
    }, 
    PhoneNumber: { 
     type: Number, 
     label: "Phone Number" 
    }, 
    User: { 
     type: String, 
     label: "User" 
    }, 
})); 

<template name="NewPerson"> 
    <div class="new-person-container"> 
    {{> quickForm collection=Person id="insertPersonForm" type="insert" class="new-person-form"}} 
    </div> 
</template> 

ありがとうございました。 コレクションスキーマに基づいてどの種類のデータを設定するかを決定します。

+0

私はこれを試してみました、残念ながら、それは問題を解決するように見えませんでした、私は試すことができる何か? – Jacques

+0

は、関数が発生するエラーに関する詳細情報を共有しており、上部(ティルテンプレート)はクライアントとサーバーフォルダの外部のファイルに配置する必要があります。 –

0

あなたはquickFormを定義するときに、コレクション名を引用する必要があります。

import { Meteor } from 'meteor/meteor' 

おそらく:

import { Person } from 'pathToYourSchemaFile' 
+0

私はコレクションを引用すると、 :テンプレートヘルパーの例外:エラー:人がウィンドウスコープにない – Jacques

+0

それに加えて、私は流星屑( '人')を取得します。 未知ReferenceError:流星が定義されていないエラー – Jacques

+0

大文字M 'Meteor.subscribe'です。 'Person'が定義されていない場合は、その定義をテンプレートヘルパーファイルにインポートする必要があります。 –

0

Meteor.subscribe('person'); 
 

 
import { Template } from 'meteor/templating'; 
 
import { ReactiveVar } from 'meteor/reactive-var'; 
 

 

 
Template.Person.onCreated(function(){ 
 
\t this.editMode = new ReactiveVar(false); 
 
\t // this.editMode = new ReactiveVar(); 
 
\t // this.editMode.set(false); 
 
}); 
 

 

 
Template.Person.helpers({ 
 
\t updatePersonId: function() { 
 
\t \t return this._id; 
 
\t }, 
 
\t editMode: function() { 
 
\t \t return Template.instance().editMode.get(); 
 
\t } 
 
}); 
 

 
Template.Person.events({ 
 
\t 'click .toggle-menu': function() { 
 
\t \t Meteor.call('toggleMenuItem', this._id, this.inMenu); 
 
\t }, 
 
\t 'click .fa-trash' : function() { 
 
\t \t Meteor.call('deletePerson', this._id); 
 
\t }, 
 
\t 'click .fa-pencil' : function(event, template) { 
 
\t \t template.editMode.set(!template.editMode.get()); 
 
\t } 
 
});
あなたにも必要な、あなたのヘルパーファイルで

<template name="NewPerson"> 
    <div class="new-person-container"> 
    {{> quickForm collection="Person" id="insertPersonForm" type="insert" class="new-person-form"}} 
    </div> 
</template> 

関連する問題