Ahm*_*tin 5 javascript meteor meteor-autoform meteor-collection2
我正在使用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};
}
}
Run Code Online (Sandbox Code Playgroud)
我在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};
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
735 次 |
| 最近记录: |