0
observeableArray를이 루프로 루프하는 방법은 무엇입니까? 기본 정보 및 보증 및 부채 종속은 동적이며 각 키는 객체 배열에 대한 참조입니다. 이 객체 안의 모든 키는 이미 알려져 있습니다.복잡한 배열의 JSON 객체와 동적 키를 사용하여 루프하는 방법은 무엇입니까?
self.filteredResults = ko.observableArray([
{
"Basic Information": [
{
"nodeId": "8",
"path": "Bookrunners/Active Bookrunners",
"tooltip": "Bookrunners/Active Bookrunners",
"resultLabel": "Active Bookrunners",
"propertyClassType": "multiselect"
},
{
"nodeId": "12",
"path": "Advisors/Auditors",
"tooltip": "Advisors/Auditors",
"resultLabel": "Auditors",
"propertyClassType": "multiselect"
},
{
"nodeId": "442",
"path": "Pricing/Amount",
"tooltip": "Pricing/Amount",
"resultLabel": "Amount",
"propertyClassType": "millions"
}
]
},
{
"Guarantees and Debt Subordination": [
{
"nodeId": "70",
"path": "Guarantees/Overview of the Guarantees/Are the Notes Guaranteed?",
"tooltip": "Guarantees/Overview of the Guarantees/Are the Notes Guaranteed?",
"resultLabel": "Are the Notes Guaranteed?",
"propertyClassType": "select"
},
{
"nodeId": "71",
"path": "Guarantees/Overview of the Guarantees/Are the Guarantees Secured?",
"tooltip": "Guarantees/Overview of the Guarantees/Are the Guarantees Secured?",
"resultLabel": "Are the Guarantees Secured?",
"propertyClassType": "boolean"
},
{
"nodeId": "80",
"path": "Guarantees/Overview of the Guarantees/Are the Guarantees Direct or Indirect?",
"tooltip": "Guarantees/Overview of the Guarantees/Are the Guarantees Direct or Indirect?",
"resultLabel": "Are the Guarantees Direct or Indirect?",
"propertyClassType": "select"
}
]
}]);
이것은 내가 지금까지 템플릿에서 시도한 것입니다. 개체 배열 내에서 첫 번째 키와 첫 번째 개체를 가져올 수 있지만 첫 번째 키만 인쇄합니다.
Basic Information
{
"propertyClassId": "8",
"path": "Bookrunners/Active Bookrunners",
"tooltip": "Basic Information/Bookrunners/Active Bookrunners",
"resultLabel": "Active Bookrunners",
"propertyClassType": "multiselect"
}
Guarantees and Debt Subordination
{
"propertyClassId": "70",
"path": "Guarantees/Overview of the Guarantees/Are the Notes Guaranteed?",
"tooltip": "Guarantees and Debt Subordination/Guarantees/Overview of the Guarantees/Are the Notes Guaranteed?",
"resultLabel": "Are the Notes Guaranteed?",
"propertyClassType": "select"
}
당신이 각 키의 마지막 두 개체가 누락 볼 수 있듯이 : 이것은 인쇄 무엇
<ul class="pull-left list-group index-search-results">
<!-- ko foreach: {data: filteredResults, as: 'result'} -->
<!--ko foreach: {data: Object.keys(result), as: 'groupHeader'}-->
<li data-bind="text: groupHeader" class="nav-header disabled "></li>
<!--ko foreach: {data: result[groupHeader], as: 'resultNode' }-->
<pre data-bind="text: ko.toJSON(resultNode, null, 2)"></pre>
<!--/ko -->
<!--/ko -->
<!-- /ko -->
</ul>
.
무엇이 여기에 있습니까?
내가 할 경우
<pre data-bind="text: ko.toJSON(filteredResults, null, 2)"></pre>
그것은 전체 목록을 인쇄합니다.
내가 처음 foreach 루프에서 할 경우
<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>
그것은 하나의 객체 만 키를 인쇄합니다.