我有一个包含要传递给自定义类的参数的对象的javascript数组。通过对象数组进行递归以创建自定义类对象
var classObjectDetails = [{
name: "objOne",
options: ["1","2"],
children: [{
name: "childOne_objOne",
options: null
children: [{
name: "childOne_childOne_objOne",
options: ["a", "b", "c", "d"],
}]
}, {
name: "childTwo_objOne",
options: null,
}]
}, {
name: "objTwo",
options: null,
}];
上面是包含详细信息的示例对象。如果我有一类像下面,
class sampleClass {
constructor(objName, option) {
this.name = objName;
this.options = option;
this.children = [];
// Some other properties
}
// Some other functions
}
我想写一个高效的递归函数里面到底还给我sampleClass对象的数组。
objOne和objTwo是在阵列中的两个对象,与具有objOne两个孩子等作为classObjectDetails
你尝试过这么远吗? – marvel308
尝试,失败,在此发布。至少在调用自己的函数中做一个循环。 – user5014677
您可以请发布预期的输出? –