【发布时间】:2017-06-13 04:50:47
【问题描述】:
当我尝试提交表单时,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;
},
});
【问题讨论】:
-
你是否也在服务器上定义了集合?
-
我不太确定应该在哪里做。我认为 Js 文件(最后一个示例)将是集合的服务器端定义。
-
您需要从服务器上的某个位置导入该集合。从您发布的代码中不清楚每段代码的确切位置以及从哪里导入。确保从服务器导入定义集合的文件(或特定于服务器的另一个集合定义文件)。
-
添加了文件的路径。我试图坚持guide 我应该在启动文件夹中的某处注册集合吗?
-
正如我之前多次提到的,检查文件是否已导入您的服务器。在浏览器控制台中打印内容并推断一切正常将导致我们无处可去。
标签: javascript meteor meteor-autoform