在向数据库插入/更新JSON数据模型之前,我使用ajv进行验证。
今天我想使用以下结构:
const dataStructure = {
xxx1234: { mobile: "ios" },
yyy89B: { mobile: "android" }
};
我的键是动态的,因为它们是ids。您知道如何使用ajv进行验证吗?
附注:作为替代方案,我当然可以使用此结构:
const dataStructure = {
mobiles: [{
id: xxx1234,
mobile: "ios"
}, {
id: yyy89B,
mobile: "android"
}]
};
那么我就必须在数组中循环查找我想要的id。所有我的查询都会变得更加复杂,这让我烦恼。
谢谢你的帮助!
xxx1234: { mobile: "ios" },
中,您需要验证xxx1234
吗? - IftekharDani{ mobile: "ios" }
? - IftekharDani