Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
流星1.4。自动表单验证消息未显示 我添加了自动成型包装(meteor add aldeed:autoform) 我添加了collection2核心包(meteor添加collection2核心) 我已经安装了siml模式(npmi——保存siml模式) 但表单仍然不能正常工作_Meteor_Meteor Autoform_Simple Schema_Meteor Collection2 - Fatal编程技术网

流星1.4。自动表单验证消息未显示 我添加了自动成型包装(meteor add aldeed:autoform) 我添加了collection2核心包(meteor添加collection2核心) 我已经安装了siml模式(npmi——保存siml模式) 但表单仍然不能正常工作

流星1.4。自动表单验证消息未显示 我添加了自动成型包装(meteor add aldeed:autoform) 我添加了collection2核心包(meteor添加collection2核心) 我已经安装了siml模式(npmi——保存siml模式) 但表单仍然不能正常工作,meteor,meteor-autoform,simple-schema,meteor-collection2,Meteor,Meteor Autoform,Simple Schema,Meteor Collection2,/导入/api/rooms/rooms.js import { Tracker } from 'meteor/tracker'; import { Mongo } from 'meteor/mongo'; import SimpleSchema from 'simpl-schema'; SimpleSchema.extendOptions(['autoform']); export const Rooms = new Mongo.Collection('rooms'); Rooms.atta

/导入/api/rooms/rooms.js

import { Tracker } from 'meteor/tracker';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);

export const Rooms = new Mongo.Collection('rooms');

Rooms.attachSchema(new SimpleSchema({
    title: {
        type: String,
        label: 'Title'
    },
    desc: {
        type: String,
        label: 'Description'
    },
    createdAt: {
        type: Date,
        autoValue(){
            return new Date();
        }
    },
}), {tracker: Tracker});
/导入/ui/pages/home.js

import { Template } from 'meteor/templating';

import './home.html';

import { Rooms } from '../../api/rooms/rooms.js'

Template.Home.helpers({
    rooms() {
        return Rooms.find({});
    },
    CollectionRooms() {
        return Rooms;
    }
});
/导入/ui/pages/home.html

<template name="Home">
    <div class="jumbotron">
        <div class="container text-center">
            <h1>Forum</h1>
            <p>“Don't raise your voice, improve your argument."</p>
        </div>
    </div>

    <div class="container-fluid bg-3">
        <h3 class="page-header">Choose your room</h3>

        {{> quickForm collection=CollectionRooms id="insertRoomsForm" type="insert"}}

        <div class="row grid-divider">
        {{#each rooms}}
            <div class="col-sm-4">
                <div class="col-padding">
                    <h3>{{title}}</h3>
                    <p>{{desc}}</p>
                </div>
            </div>
        {{/each}}
        </div>
    </div>
</template>
我看到表单,它将记录插入数据库,但验证消息没有显示,为什么会有字段“created at”?我做错了什么?

您的架构中有一个输入错误,导致未包含跟踪器。这最终会导致表单没有(反应性)验证消息。更正后的代码为:

Rooms.attachSchema(new SimpleSchema({
    title: {
        type: String,
        label: 'Title'
    },
    desc: {
        type: String,
        label: 'Description'
    },
    createdAt: {
        type: Date,
        autoValue(){
            return new Date();
        }
    },
}, {tracker: Tracker}));

您的模式中有一个输入错误,导致未包含跟踪器。这最终会导致表单没有(反应性)验证消息。更正后的代码为:

Rooms.attachSchema(new SimpleSchema({
    title: {
        type: String,
        label: 'Title'
    },
    desc: {
        type: String,
        label: 'Description'
    },
    createdAt: {
        type: Date,
        autoValue(){
            return new Date();
        }
    },
}, {tracker: Tracker}));

您能否尝试执行
AutoForm.debug()
,然后重新提交表单,看看是否有错误您希望它显示什么验证消息?如果您提交一个空白表单,数据库中存储了什么?其次,显示的是
createdAt
,因为它是由您在模式中指定的。如果需要将其作为隐藏字段,请使用:
createdAt:{type:Date,autoValue(){return new Date();},autoform:{type:“hidden”}
@blueren感谢您的帮助,了解autoValue,我认为它会使字段被默认值隐藏。您可以尝试执行
AutoForm.debug()
,然后重新提交表单,看看是否有错误您希望它显示什么验证消息?如果您提交一个空白表单,数据库中存储了什么?其次,显示的是
createdAt
,因为它是由您在模式中指定的。如果您需要它是一个隐藏字段,那么使用:
createdAt:{type:Date,autoValue(){return new Date();},autoform:{type:“hidden”}
@blueren感谢您帮助我们找到autoValue,我认为它可以通过default隐藏字段谢谢,是的,你是对的,编程使人失明)。我浪费了很多时间。你救了我的命)谢谢,是的,你是对的编程让人失明)。我浪费了很多时间。(你救了我的命)