我有一个设置验证规则,该规则将应用于一组对象。我需要更深入地研究“ contentType”并编写验证。
{
"_id" : ObjectId("5b3570f3150a0b57a4e7421e"),
"children" : [
{
"fullName" : "John doe",
"yearGroup" : "4",
"absences" : [],
"id" : "765"
}
],
"email" : "jdoe@gmail.com",
"firstName" : "John",
"lastName" : "Doe",
"role" : "parent",
"__v" : 1
下面的验证可以访问“ obj键”和“规则键”。
我无法更深入地了解我们在哪里可以访问rule [key]的键和obj [key]的键。
var rules= {
p1: {
required:true,
pgName:"string",
maxLength:5,
contentType: {main:"string", Id: "string"}
},
p2: {
required:true,
pgName:"string",
maxLength:5
},
p3: {
required: true,
pgName:"string",
maxLength:5,
contentType: {sub:"string", Id: "string"}
}
}
obj= {
p1: {
pgName:"page1",
contentType: {main:"template obj", Id: "af3323443"}
},
p2: {
pgName:"page2",
},
p3: {pgName:"page3",
contentType: {main:"template obj2", Id: "af35455"}}
};
我需要包括“ contentType”属性,以使用上面的代码进行验证。