请求Meteor+自动成型示例

Meteor + autoform example requested

本文关键字:成型 Meteor+ 请求      更新时间:2023-12-16

在自动表单文档中,有许多示例片段,但我无法使其中任何一个发挥作用。主要是因为自动成型、流星和JS对我来说都是新的

然而,我很善于改编例子,但找不到任何简单的例子。这是一个我挣扎的问题。我能得到一个使用集合的简单自动表单(或快速表单)的完整示例吗?

  1. 假设我已经安装了aldeed:autoform和aldeed:collection2
  2. 假设我的文件被划分为

    • both/testform.js
    • server/testform.js
    • client/testform.js
    • client/testform.js
  3. 假设我使用的是一个名为"testTemplate"的模板和一个称为"testCollection"的集合

谢谢你的帮助。

我会尽量简化它。

首先创建项目并删除autopublish and insecure

第二个放在/server/testform.js上。

TestCollection.allow({
  insert:function(){return true;},
  remove:function(){return true;},
  update:function(){return true;},
})

以及发布功能

Meteor.publish("TestCollection", function () {
  return TestCollection.find();
});

关于允许/拒绝规则的更多信息

按照Meteor最佳实践,将集合声明放在/lib/testform.js中,而不是/both/testform.js,以确保首先对其进行评估。

TestCollection = new Mongo.Collection("TestCollection");

以及订阅。

if(Meteor.isClient){
     Meteor.subscribe('TestCollection')
}

现在使用/client/testform.html

放这个。

<template name="testForm">
  {{> quickForm collection="TestCollection" id="insertTestForm" type="insert"}} 
</template>

现在在/client/testform.js上放置模式

TestCollection.attachSchema(new SimpleSchema({ //take this from docs.
  title: {
    type: String,
    label: "Title",
    max: 200
  },
  author: {
    type: String,
    label: "Author"
  },
  copies: {
    type: Number,
    label: "Number of copies",
    min: 0
  },
  lastCheckedOut: {
    type: Date,
    label: "Last date this book was checked out",
    optional: true
  },
  summary: {
    type: String,
    label: "Brief summary",
    optional: true,
    max: 1000
  }
})); 

注意

如果你是Meteor/Javascript的新手,不要跳到像这样复杂的包中。

运行这个,看看它们是如何工作的。

meteor create --example todos 
meteor create --example local market

或者看看流星教程

对于Javascript,本教程/指南对我如何正确学习Javascript有很大帮助。