我会尽量简化。
首先创建项目并删除autopublish and insecure 包
第二个/server/testform.js放这个。
TestCollection.allow({
insert:function(){return true;},
remove:function(){return true;},
update:function(){return true;},
})
和publish 函数
Meteor.publish("TestCollection", function () {
return TestCollection.find();
});
更多关于allow/deny规则
根据 Meteor 最佳实践,将集合声明放在 /lib/testform.js 中,而不是 /both/testform.js,以确保首先对其进行评估。
TestCollection = new Mongo.Collection("TestCollection");
还有subscription。
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
或查看the meteor tutorial
对于 Javascript,本教程/指南对我有很大帮助 How to Learn Javascript properly