Как пропустить этот filteredResults
наблюдаемый массив, учитывая, что все первые ключи, например. Базовая информация и гарантии и субординация задолженности являются динамическими, и каждый ключ является ссылкой на массив объектов. Известны все ключи внутри этого объекта, с другой стороны.Как пропустить сложный массив объектов 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"
}
]
}]);
Это то, что я пробовал до сих пор в своем шаблоне. Я могу получить первые ключи и первый объект в массиве объектов, но он только когда-либо печатает первый.
<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>
Это то, что он печатает:
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"
}
Как вы можете видеть, что не хватает двух последних объектов для каждого ключа.
Что мне здесь не хватает?
Если я:
<pre data-bind="text: ko.toJSON(filteredResults, null, 2)"></pre>
Он печатает весь список.
Если я под первую петлю Еогеасп:
<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>
Он печатает только ключ с одного объекта.