I'm working with json schema form objects, and we have very deeply nested ones. In order to add new features, sometimes we need to 'do the same thing' to every child object that matches certain criteria.
The root object is like
"MainApplicant": {
"type": "object",
"title": "Main Applicant",
"properties": {
"birthDetails": {
"type": "object",
"title": "Birth Details",
"key": "birthDetails",
"properties": {
"dateOfBirth": {
"type": "string",
"title": "Date of Birth",
"key": "dateOfBirth",
"format": "date"
},
"countryOfBirth": {
"type": "string",
"title": "Country of Birth",
"key": "countryOfBirth",
},
},
It can go any number of tiers deep.
Right now im doing what i need to do by doing..
Object.keys(properties).forEach(function(key) {
// console.log("dealing with key ",key,properties[key])
if (uischema[key] == undefined) {
uischema[key] = {}
}
if (properties[key].type == "object") {
console.log(key + " is a lvl2 Object!")
Object.keys(properties[key].properties).forEach(function(key2) {
if (uischema[key][key2] == undefined) {
uischema[key][key2] = {}
}
if (properties[key].properties[key2].type == "object") {
// console.log(key2 + " is a lvl3 Object!",properties[key].properties[key2].properties,uischema[key])
Object.keys(properties[key].properties[key2].properties).forEach(function(key3) {
if (uischema[key][key2][key3] == undefined) {
uischema[key][key2][key3] = {}
}
if (properties[key].properties[key2].properties[key3].type == "object") {
essentially, looping thru each tier manually.in this case, we're simply switching undefined to become an empty object.
its super lame but i have no idea how to write a looping function for it.
almost fell for a joke library that allows goto in javascript!