【发布时间】:2017-08-06 08:12:26
【问题描述】:
我有一个类,其中包含这样的键、值和子项
class Container{
key: string,
value: string,
children: Container[]
}
function searchKey(container: Container, key:string){
if (container.key == key) {
return container;
}
else if (container.children.length>0){
for (let child of container.children) {
let found = searchKey(child, key);
if (found != null) {
return found;
}
}
}
return null;
}
我将提供给 searchKey() 函数的输入将是一个包含深度对象的数组,我想获取提供的键参数的值。但是当前的 searchKey() 函数不接受数组。如何让它使用数组作为输入?
【问题讨论】:
-
不应该是函数searchKey(container: Container[], key:string){
-
@marvel308 如果我将容器参数设为数组,我无法递归调用 searchKey() 函数
-
你不能做另一个函数来接受一个数组并将这个searchKey作为一个实用程序调用吗?
标签: javascript arrays typescript microsoft-distributed-file-system