繁体   English   中英

流星自动表单“找不到方法'/ insert'[404]”

[英]Meteor Autoform “Method '/insert' not found [404]”

我有这种奇怪的行为,当我尝试提交表单时,autoform包会抛出404。

我希望我得到安装说明和基本的演示权利。 我尝试提供所需的文件。 首先,请使用Schema,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;
  },
});

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

服务器/main.js

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

(进口/启动/服务器/ index.js)

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

您应该检查是否正在使用“不安全”模块,

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM