我是meteor 和autoform 的新手,正在尝试将表单插入到mongo 中。无论我改变什么,它都不会起作用。我不知道下一步该尝试什么。
我已经删除了不安全和自动发布。附件是我的 .js 和 html 文件的链接。
我已经设置了一个方案,让表单完美地显示在 html 上。现在,当我点击提交时,没有任何内容被放入 mongo 中。我有允许规则设置。我显示了大量的 console.logs,它们都会触发并跟随,就好像帖子成功一样。事实上,在 onSuccess 中我得到了一个文档编号,但我的数据库中没有任何内容。
非常感谢这里的任何帮助。我知道这一定是小事,但我已经绞尽脑汁进行了几个小时的无休止的搜索。
.js 文件没有方案。 plnkr链接中的完整js文件
if (Meteor.isClient) {
// ********************************************************
// *** Creating the database scheme for the customer account
// ********************************************************
customers = new Mongo.Collection("customer");
AutoForm.debug();
var postHooks = {
before: {
insert: function(doc) {
console.log("Getting to posting hooks");
if(Meteor.userId()){
doc.createdUser = Meteor.userId();
doc.createdDate = Date();
console.log("Got to the insert before hook!");
}
return doc;
}
},
after: {
// Replace `formType` with the form `type` attribute to which this hook applies
insert: function(error, result) {
console.log("Getting to the after insert function");
console.log(error);
console.log(result);
console.log("New Document ID is " + this.docId);
}
},
onSuccess: function(formType, result) {
console.log("Getting to the insert sucess area");
console.log(result);
},
onError: function(formType, error) {
console.log(error);
}
}
AutoForm.addHooks('insertCustomer', postHooks);
Template.customerTemplate.helpers({
showLoginError: function(){
return showCustomerSaveError;
}
});
}
if (Meteor.isServer) {
customers = new Mongo.Collection("customer");
customers.allow({
insert: function (userId, doc) {
console.log("Getting to the insert server call");
// the user must be logged in
return !! userId;
},
update: function (userId, doc, fields, modifier) {
// can only change your own documents
return doc.owner === userId;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
},
fetch: ['owner']
});
}
最佳答案
您正在将文件添加到数据库,但不发布它。
运行 meteor add autopublish
或 checkin MongoDB 本身以查看文档。
关于javascript - Meteor:Autoform 未向 mongo 提交帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32471028/