У меня есть рекурсивная структура данных (рекурсивная через свойство children
), как показано ниже:
export interface IExecutableLog {
round: number;
log: string;
}
export interface IExecutableResult {
uid: string;
name: string;
desc: string;
status: string;
passedRounds: number;
totalRound: number;
children?: IExecutableResult[];
statementType?: string;
logs?: IExecutableLog[];
}
export interface ISummary {
title: string;
jobName: string;
timestamp: Date;
tester: string;
result: string;
executionId: string;
testJobId: string;
resultDetails: IExecutableResult;
}
И я хочу отображать данные типа Isummary из бэкэнда.
Я попытался определить компонент, как показано ниже:
// pats-report-element.component.ts
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { IExecutableResult } from '../pats-report.interface';
@Component({
selector: 'pats-report-element',
templateUrl: 'app/report/basic/pats-report-element.html',
encapsulation: ViewEncapsulation.None,
})
export class PatsReportElementComponent {
@Input()
public data: IExecutableResult;
}
// app/report/basic/pats-report-element.html
<tr>
<td>{{data?.name}}</td>
<td>{{data?.status}}</td>
<td>{{data?.rounds}}</td>
<td>{{data?.passedRounds}}</td>
<td>{{data?.rounds > 0 ? (data.passedRounds / data.rounds) * 100 + "%" : "NA"}}</td>
<td>{{data?.timestamp | date:"y-MM-dd HH:mm:ss"}}</td>
</tr>
<template [ngIf]="data && data.children">
<template ngFor let-item [ngForOf]="data.children" let-i="index">
<pats-report-element [data]="item"></pats-report-element>
</template>
</template>
Но визуализированный DOM будет включать элемент хоста 'pats-report-element', который недействителен внутри <table></table>
tag. DOM выглядит следующим образом:
Я проверил документ angular2 и, похоже, attribute-directives является правильный выбор. Но я не могу найти способ использовать шаблон с директивами атрибутов так же, как я делаю в PatsReportElementComponent.
Каков правильный способ достижения моей цели?
[Обновление 1]
Попробовал предложение @Günter Zöchbauer, но все еще не решил мою проблему. Визуализированный DOM все еще не такой, как ожидалось (<tr></tr>
все еще не сглажен).
*ngFor
над сглаженными данными. - person Günter Zöchbauer   schedule 25.08.2016