0
私は次のようなスキーマを使用しています。
をご参照のうえ、アレイフィールドに関連アイテムを追加できます。関連アイテムアレイフィールド。私は重複を取得しないように -カスタムオブジェクトを検証する配列にプッシュ
私は同様のオブジェクトが既に配列に存在するかどうかをテストする項目の関連アイテムへフィールドを、押しだオブジェクトをカスタム検証したいと思います。
以下のコードでは、カスタム検証は実行されません。カスタムバリデーションはtype: [object]
に適用できないため、オブジェクトのプロパティに適用する必要がありますが、オブジェクト全体をテストすることはできません。
const ItemsSchema = new SimpleSchema({
name: {
type: String,
label: 'Name',
},
related: {
type: [Object],
label: 'Related Items',
optional:true,
custom: function() {
let queryData = { docId: this.docId, related: this.value }
if (Meteor.isClient && this.isSet) {
Meteor.call("relatedObjectIsUniqueForThisItem", queryData,
function (error, result) {
if(!result){
console.log("not unique");
return "Invalid";
}
else{
return true;
}
});
}
}
},
'related.$.name':{
type: String,
label:'Name',
},
'related.$.code':{
type:String,
label:'Code',
min:5,
},
});