[英]IE9/10: Meteor.users.attachSchema - Object doesn't support property or method 'attachSchema' using Collection2 in Meteor.js
[英]Collection2 doesn't clean data when using $push
我正在使用collection2将表单中的数据插入到SimpleSchema中。 Collection2应该在插入之前清除数据,但是,如果我使用$ push插入数组,则不会清除数据。 所有没有数据的字段都包含""
。 据我所知,不可能使用$ set清除数据。 我想念什么?
片段: Schema
const ProfileCandidateSchema = new SimpleSchema({
careerHistoryPositions: { type: Array, optional: true },
'careerHistoryPositions.$': { type: Object, optional: true },
'careerHistoryPositions.$.uniqueId': { type: String, optional: true },
'careerHistoryPositions.$.company': {
type: String,
optional: true,
custom: function () {
const shouldBeRequired = this.field('careerHistoryPositions.company').value;
if (!shouldBeRequired) {
// updates
if (this.isSet) {
if (this.operator === '$set' && this.value === null || this.value === '') return SimpleSchema.ErrorTypes.REQUIRED;
}
}
}
}
}, {
clean: {
filter: true,
autoConvert: true,
removeEmptyStrings: true,
trimStrings: true,
getAutoValues: true,
removeNullsFromArrays: true
}
});
片段: Update
const updatePosition = this.state.careerHistoryPositions.map((position) => {
ProfileCandidate.update({
_id: this.state.profileCandidateCollectionId
}, {
$push: {
'careerHistoryPositions': {
uniqueId: position.uniqueId,
company: position.company
}
}
});
});
您可以使用$set
初始化数组,方法是在要插入的对象周围使用方括号:
const updatePosition = this.state.careerHistoryPositions.map((position) => {
ProfileCandidate.update(this.state.profileCandidateCollectionId, {
$set: {
careerHistoryPositions: [{
uniqueId: position.uniqueId,
company: position.company
}]
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.