我有一个json对象,它有一个名为data的内部对象,其中包含数据:{count: 9,message:“9个站点同步”}--也是json对象。我试着从消息中得到价值,而不是从计数中得到。下面是我的模板代码:
<div class="full-width border-radius-4 overflow-hidden">
<!-- Header -->
<div class="head accent p-24 pb-16" fxLayout="column" fxLayoutAlign="space-between">
<div fxLayout="row" fxLayoutAlign="end center">
</div>
</div>
<mat-accordion class="full-width example-headers-align" multi *ngIf="liveActions$ | async as actions; else: loading">
<mat-expansion-panel *ngFor="let action of actions">
<mat-expansion-panel-header *ngIf="action.type == 'single'">
<mat-panel-description fxFlex="30%">
<div class="lgreen material-icons" *ngIf="action.status == 'completed'">done_all</div>
<div class="red material-icons" *ngIf="action.status == 'pending'">pending_actions</div>
<div class="blue material-icons" *ngIf="action.status == 'queued'">pending</div>
<div class="yellow material-icons" *ngIf="action.status == 'error'">error</div>
</mat-panel-description>
<mat-panel-description fxFlex="40%">{{action.key}}</mat-panel-description>
<div *ngFor="let dataItem of action?.data | keyvalue">{{dataItem?.value?.message}}
</div>
<!-- <mat-panel-description>{{action.startDate | date:'medium'}}</mat-panel-description>-->
</mat-expansion-panel-header>
</div>
</mat-expansion-panel>
</mat-accordion>
<ng-template #loading>Loading…</ng-template>
</div>当我做{{dataItem?.value?.message}}时,我什么也得不到。当我做dataItem.value时,我会得到计数和消息的值。
我只需要消息中的值。我做错什么了??
发布于 2021-02-23 21:26:51
使用对象上的键值管道,它将将action.data对象转换为下面的数组
[{key:count, value: 9}, {key:message,value:'9 sites synced'}]如果在上面的对象上迭代:
dataItem?.value?.message = undefined
dataItem.value = 9 and 9 sites synced这就是你所看到的。
绑定要显示的值时,只需添加一个条件。
{{ dataItem.key === 'message' ? dataItem.value: ' '}}还有其他的方法.我认为你现在可以根据你的要求搞清楚发生了什么,需要做什么。
https://stackoverflow.com/questions/66340738
复制相似问题