流星自动成型 "Method '/insert' not found [404]"

Meteor Autoform "Method '/insert' not found [404]"

当我尝试提交表单时,autoform 包抛出 404 错误。

我希望我能正确理解安装说明和基本演示。 我尝试提供所需的文件。对于初学者,模式、Html 和 JS 文件。

架构(imports/api/footballs/footballs.js):

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';


SimpleSchema.extendOptions(['autoform']);

export const Footballs = new Mongo.Collection('footballs');

Footballs.attachSchema (new SimpleSchema({
  playerone: {
    type: String,
    label: 'Player One',
    max: 255,
  },
  playertwo: {
    type: String,
    label: 'Player Two',
    max: 255,
  },
  gamedate: {
    type: Date,
    label: 'Game Data',
    autoValue: function autoValueCreatedAt() {
      return new Date();
    },
    autoform: {
      type: 'hidden'
    },
  },
},
{tracker: Tracker}));

HTML (imports/ui/pages/stadium.html)

<template name="stadium">
  <h1>Lets play kicker!</h1>
  {{> quickForm collection=footballCollection id="insertFootballsForm" type="insert" class="newFootballForm"}}
</template>

JS (imports/ui/pages/stadium.js)

import {Footballs} from '../../api/footballs/footballs.js';
import { Template } from 'meteor/templating';

import './stadium.html';

Template.stadium.helpers({
  footballCollection(){
    return Footballs;
  },
});

您应该检查您是否使用 'insecure' 模块,

meteor list

如果不在列表中,您可以

meteor add insecure

或者,在集合定义之后添加。

Footballs.allow( { 
    insert() { 
        /*here goes the logic to determine if someone is allowed*/
        return true; 
    },
    update() { return true; },
    remove() { return true; }
} )

顺便说一句,如果您直接使用集合,则可以在模板上使用它而不是编写帮助程序:

{{> quickForm collection="footballs" id="insertFootballsForm" type="insert" class="newFootballForm"}}

感谢@MasterAM 耐心等待,这是解决方案。该集合确实不存在于服务器端,因此必须导入。这并没有发生。

Server/main.js

import '../imports/startup/server';

(imports/startup/server/index.js)

import { Footballs } from '../../api/footballs/footballs.js';