Autoform:变量不在窗口范围内

时间:2017-10-22 23:08:57

标签: meteor meteor-blaze meteor-autoform

我试图通过在其上附加架构来在网站的主页面上显示一个autoform。

我收到以下错误:

  

未捕获错误:库存不在窗口范围内

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'
    }
}));

主要模板

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

1 个答案:

答案 0 :(得分:1)

在订购建议中为您提供2种解决方案。

  

解决方案编号1 :只需在.js文件中创建一个简单的帮助函数,如下所示,

<强> 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}}
  

解决方案No.2 :在Main.js客户端文件中导入集合并将其添加到窗口范围。

<强> Main.js

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

window.Inventory = Inventory;

<强> main.html中

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

注意:有关详情,click here