1
개체가 포함 된 변수 키 이름을 가진 개체가 있습니다. 개체에 대해 깊이 우선 검색 (DFS)을하고 싶습니다.중첩 된 ng-repeat를 사용하여 깊이 우선 검색
예 개체 :
object = { "var1" : {
"var2a" : {
"someKey" : someValue
},
"var2b" : {
"someKey" : someOtherValue
}}}
다음과 같이 DFS에서 내 시도가 (작동하지 않을 것이다)입니다
:
<div ng-repeat = "child in object">
<div ng-repeat = "grandChild in child ">
<td> {{grandChild.aKey}}</td>
</div>
</div>
내가 다른 사람 in this previous question의 접근을 보았다, 그러나 이것은하지 않습니다 변수 키 이름 때문에 저에게 도움이됩니다.
또한 개체의 깊이도 알려져 있습니다.
우리는 child
의 결과가 무엇인지 확인하려면이 코드를 사용하는 경우 :
{"var2a" : {
"someKey" : someValue
}}
편집 : : 그것은 할 수있을 수
<div ng-repeat = "child in object">
<td> {{child}}</td>
<div ng-repeat = "grandChild in child ">
<td> {{grandChild.aKey}}</td>
</div>
</div>
우리는
child
의 첫 번째 인스턴스가 될 수 콘솔로 출력 할이 JavaScript DFS 스 니펫을 활용 하시겠습니까?
angular.forEach(object,function(child,value){
angular.forEach(child,function(grandChild,value){
console.log(grandChild.someKey)
});
});