javascript – 使用autoform验证Meteor方法的模式
作者:互联网
我正在使用autoform,collection2.我想使用方法调用类型进行插入/更新,因为我想在保存到服务器中的数据库之前添加其他字段. SimpleSchema会检查客户端中的数据,但是如何根据服务器端的模式检查数据呢?我添加新数据的方法如下:
Meteor.methods({
companyAdd: function (companyAttr) {
// add additional fields to document
var currentDate = new Date();
var company = _.extend(companyAttr, {
createdBy: user._id,
createdAt: currentDate
});
var newCompanyId = Companies.insert(company);
return {_id: newCompanyId};
}
}
解决方法:
我在simpleschema的文档中找到了,如果其他人以后需要解决方案:你可以检查架构:
Meteor.methods({
companyAdd: function (companyAttr) {
//here we check the data sent to method against the defined schema
check(companyAttr, Companies.simpleSchema());
var currentDate = new Date();
var company = _.extend(companyAttr, {
createdBy: user._id,
createdAt: currentDate
});
var newCompanyId = Companies.insert(company);
return {_id: newCompanyId};
}
}
标签:javascript,meteor,meteor-autoform,meteor-collection2 来源: https://codeday.me/bug/20190519/1138026.html