Meteor方法错误-架构允许[验证错误]
我得到以下错误,不知道为什么我很确定我做的每件事都是正确的。我正在传递一个对象数组,并根据它进行验证 方法Meteor方法错误-架构允许[验证错误],meteor,simple-schema,Meteor,Simple Schema,我得到以下错误,不知道为什么我很确定我做的每件事都是正确的。我正在传递一个对象数组,并根据它进行验证 方法 export const insert = new ValidatedMethod({ name: 'lineups.insert', // Validation validate(args) { console.log(args); new SimpleSchema({ business: { type:
export const insert = new ValidatedMethod({
name: 'lineups.insert',
// Validation
validate(args) {
console.log(args);
new SimpleSchema({
business: { type: [Object] },
competitors: { type: [Object] },
location: { type: Object },
type: { type: String }
}).validate(args)
},
// Run
run({ lineupsId}) {
const loggedInUser = Meteor.user();
// check user roles
if (!loggedInUser) {
throw new Meteor.Error(403, 'Access Denied');
}
}
});
下面是该方法获取的参数
Object {business: Array[1], competitors: Array[1], location: Object, type: "Business Analysis"}
但是我得到了以下错误
架构不允许business.0.placeID[验证错误]
调用方法
let businessArray = $.map(Session.get('business'), function(value, index) {
return [{placeID:value.place_id, name:value.name}];
});
insert.call({
business: businessArray,
competitors: Session.get('competitors'),
location: Session.get('location'),
type:Session.get('type')
}, (err, res) => {
if (err) {
if (ValidationError.is(err)) {
toastr.error(err.message);
}
} else {
toastr.error('Success, lineup have been created');
}
});
因此,问题在于验证,您还需要验证每个对象值 可以这样做吗
validate: new SimpleSchema({
type: { type: String },
business: { type: [Object] },
'business.$.name': { type: String },
'business.$.placeID': { type: String }
}).validator(),
另一个选项是这样的,但有了它,我无法运行该方法来执行
validate(args) {
new SimpleSchema({
business: [{ placeID: String, name: String }],
competitors: { type: [Object] },
location: { type: Object },
type: { type: String }
}).validator(args)
},
因此,问题在于验证,您还需要验证每个对象值 可以这样做吗
validate: new SimpleSchema({
type: { type: String },
business: { type: [Object] },
'business.$.name': { type: String },
'business.$.placeID': { type: String }
}).validator(),
另一个选项是这样的,但有了它,我无法运行该方法来执行
validate(args) {
new SimpleSchema({
business: [{ placeID: String, name: String }],
competitors: { type: [Object] },
location: { type: Object },
type: { type: String }
}).validator(args)
},
试试这个
validate(args) {
console.log(args);
new SimpleSchema({
business: { blackbox: true, type: [Object] },
competitors: { blackbox: true, type: [Object] },
location: { blackbox: true, type: Object },
type: { type: String }
}).validate(args)
},
试试这个
validate(args) {
console.log(args);
new SimpleSchema({
business: { blackbox: true, type: [Object] },
competitors: { blackbox: true, type: [Object] },
location: { blackbox: true, type: Object },
type: { type: String }
}).validate(args)
},
此解决方案的缺点是无法验证对象属性。在某些情况下,这没什么大不了的,但值得记住。这是真的,在我的情况下,我通常在写下DB之前做一些JS验证。这种解决方案的缺点是不会验证对象属性。在某些情况下,这没什么大不了的,但值得记住。这是真的,在我的情况下,我通常在写下DB之前做一些JS验证。