请求Meteor + autoform示例

Wes*_*des 3 javascript node.js meteor

autoform docs中,有许多代码片段,但我无法使它们中的任何一个工作.主要是因为autoform,meteor,最后JS对我来说都是新手.

但是,我擅长调整示例,但找不到任何简单的示例.这是我努力奋斗的一个.我可以使用集合获得一个简单的autoform(或quickform)的完整示例吗?

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

    • 两者/ testform.js
    • 服务器/ testform.js
    • 客户机/ testform.js
    • 客户端/ testform.js?
  3. 让我们说我正在使用一个名为"testTemplate"的模板和一个名为"testCollection"的集合

谢谢您的帮助.

Eth*_*aan 7

我会尽力做到.

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

第二个就是/server/testform.js这个.

TestCollection.allow({
  insert:function(){return true;},
  remove:function(){return true;},
  update:function(){return true;},
})
Run Code Online (Sandbox Code Playgroud)

发布功能

Meteor.publish("TestCollection", function () {
  return TestCollection.find();
});
Run Code Online (Sandbox Code Playgroud)

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

而不是根据Meteor最佳实践/both/testform.js放置集合声明,/lib/testform.js以确保首先评估它.

TestCollection = new Mongo.Collection("TestCollection");
Run Code Online (Sandbox Code Playgroud)

订阅.

if(Meteor.isClient){
     Meteor.subscribe('TestCollection')
}
Run Code Online (Sandbox Code Playgroud)

从今起 /client/testform.html

把这个.

<template name="testForm">
  {{> quickForm collection="TestCollection" id="insertTestForm" type="insert"}} 
</template>
Run Code Online (Sandbox Code Playgroud)

现在/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
  }
})); 
Run Code Online (Sandbox Code Playgroud)

注意

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

运行它,看看它们是如何工作的.

meteor create --example todos 
meteor create --example local market
Run Code Online (Sandbox Code Playgroud)

或者看一下流星教程

对于Javascript本教程/指南帮助我很多如何正确学习Javascript