在自动表单文档中,有许多示例片段,但我无法使用其中的任何示例。主要是因为autoform,流星和JS对我来说都是新手。
但是,我擅长改编示例,但是找不到任何简单的示例。这是我努力的目标。我可以使用集合获得一个简单的自动表单(或快速表单)的完整示例吗?
假设我的文件分为
假设我使用的是名为“ 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的最佳做法,而不是/both/testform.js
放入集合声明,/lib/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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句