2017-10-22 5 views
0

ウェブフォームのメインページにスキーマを添付して自動フォームを表示しようとしています。Autoform:変数がウィンドウスコープにありません

私は次のエラーを取得する:

Uncaught Error: Inventory is not in the window scope

server.js

SimpleSchema.extendOptions(['autoform']); 

import SimpleSchema from 'simpl-schema'; 

Inventory = new Mongo.Collection('inventory'); 
Inventory.attachSchema(new SimpleSchema({ 
    customTonerName: { 
     type: String, 
     label: 'Custom Toner' 
    }, 
    quantity: { 
     type: Number, 
     label: 'Quantity' 
    } 
})); 

メインテンプレート:あなたはこのために2つのソリューションを提供

{{#autoForm collection="Inventory" id="insertInventoryForm" type="insert"}} 
    {{> afQuickField name='quantity'}} 
{{/autoForm}} 
+0

は、 "現在のスコープ内にある"ヘルパー "または"プロパティ "または"変数 "をインベントリ" –

答えて

1

推薦順に並べる。

Solution No. 1 : Just make a simple helper function in .js file as below,

Main.js

import { Inventory } from 'your location'; // mention path here 

Template.Main.helpers({ 
    Inventory(){ 
    return Inventory; 
    } 
}); 

main.htmlを

{{#autoForm collection=Inventory id="insertInventoryForm" type="insert"}} 
    {{> afQuickField name='quantity'}} 
{{/autoForm}} 

Solution No.2 : Import your collections on a Main.js client file and add them to the window scope.

Main.js

引用符、 `コレクションは= "インベントリ"`、 `、引用符なしのに対し、 "`window.Inventory`を探して" という意味のコレクション= Inventory`付き
import { Inventory } from 'your location'; // mention path here 

window.Inventory = Inventory; 

main.htmlを

{{#autoForm collection="Inventory" id="insertInventoryForm" type="insert"}} 
    {{> afQuickField name='quantity'}} 
{{/autoForm}} 

Note: For more insight on this , click here

関連する問題