我正在编写一个家谱应用程序,但无法动态地将孩子与父母联系起来。我不断收到父母未定义的错误。由于使用相同的函数来创建父级,我不知道如何识别父级,而不是在再次调用该函数时通过变量名传递它。
非常感谢任何可以为我指明正确方向的人。我显然不是很精通javascript。
更新:我能够通过将每个函数调用分配给适当的名称变量来解决问题。感谢@Oriol 下面的帮助!
var rafael_bravo = addFamilyMember("rafael_bravo", "Rafael Bravo", "-", "-", "-", god, "GeneralPartner");
var calixta_otero = addFamilyMember("calixta_otero", "Calixta Otero", "-", "-", "-", rafael_bravo, "LimitedPartner");
var omar_bravo = addFamilyMember("omar_bravo", "Omar Bravo", "-", "-", "-", rafael_bravo, "LimitedPartner");
function addFamilyMember (child,name,dob,dod,img,parent,link) {
child = new primitives.orgdiagram.ItemConfig();
child.name = name;
child.birth = dob;
child.death = dod;
child.image = "includes/images/" + img + ".png";
child.templateName = "familyTemplate";
parent.items.push(child);
jQuery(".basicdiagram").orgDiagram("update", primitives.orgdiagram.UpdateMode.Refresh);
return child;
}