problem description
I"m going to loop through this array now
{
father: "",
mother: "",
husband: "",
wife: "",
brother: "",
sister: "",
son: "",
daughter: "",
};
I want to get the values of father, mother, husband and wife from the outside to decide whether to display father, mother, husband and wife in the loop. How to achieve this?
for example, if I get an empty value of my father externally, then show my father"s output in the loop
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)
function getMenu(d) {
//
var father = {};
function getFather(d) {
let arr = data;
return arr.find(function (item, index, arr) {
if (item.people.id == d.uid) {
return father
}
})
};
//
var mother = {};
function getMother(d) {
var fatherId = getFather(d).rel.father.id;
let arr = data;
return arr.find(function (item, index, arr) {
if (item.rel.husband) {
if (item.rel.husband.id == fatherId) {
return mother;
}
}
})
};
//alert(mother + "");
//alert(father + "");
//
var relAliasData = {
father: "",
mother: "",
husband: "",
wife: "",
brother: "",
sister: "",
son: "",
daughter: "",
};
let a = "";
let obj = relAliasData;
let newObj = d;
for (var m in obj) {
if (!d[m]) {
a += ":" + obj[m]
}
}
alert(a)
}
what result do you expect? What is the error message actually seen?
when mom and dad are already equivalent in the data, the output of mom and dad in the circular array is not allowed to be displayed