Mein Ziel Eigenschaften ist einzustellen, wie Name, versteckt und no_parent dynamisch festgelegt, aber es hält mich geben:Kann nicht eine Eigenschaft dynamisch in einem Objekt
TypeError: Cannot set property 'name' of undefined
Auch wenn ich scorcroot
initialisiert, bevor es durch Parameter. Hier
ist der Code:
adattamento: function(data) {
var continua = true;
var scorcfat = this.famiglia;
var scorcroot = {};
this.controlloprimi(scorcroot, scorcfat);
this.root = scorcroot;
console.log("hey!")
console.log(this.root);
},
controlloprimi: function(scorcroot, scorcfat) {
scorcroot.name = scorcfat.name;
scorcroot.hidden = false;
scorcroot.no_parent = true;
if (scorcfat.father != null) {
if (scorcfat.mother != null) {
scorcroot.children = [{}, {}, {}];
this.controlloprimi(scorcroot.children[1], scorcfat.father);
scorcroot.children[2].name = "";
scorcroot.children[2].hidden = true;
scorcroot.children[2].no_parent = false;
this.controlloprimi(scorcroot.children[3], scorcfat.mother)
} else {
scorcroot.children = [{}]
this.controlloprimi(scorcroot.children[1], scorcfat.father);
}
}
if (scorcfat.mother != null) {
scorcroot.children = [{}, {}];
this.controlloprimi(scorcroot.children[1], scorcfat.mother);
}
},
Stellen Sie sicher, 'scorcroot.children [2 ] 'ist nicht' undefiniert'. Nur ein Zeiger, index in JS startet von 0 und nicht 1 – Rajesh
Ja, das Problem sind die Zahlen ... Vielen Dank – ImFireblade