首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能使用键值对到达内物体的角度与火基

不能使用键值对到达内物体的角度与火基
EN

Stack Overflow用户
提问于 2021-02-23 20:36:44
回答 1查看 38关注 0票数 1

我有一个json对象,它有一个名为data的内部对象,其中包含数据:{count: 9,message:“9个站点同步”}--也是json对象。我试着从消息中得到价值,而不是从计数中得到。下面是我的模板代码:

代码语言:javascript
复制
<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&hellip;</ng-template>
</div>

当我做{{dataItem?.value?.message}}时,我什么也得不到。当我做dataItem.value时,我会得到计数和消息的值。

我只需要消息中的值。我做错什么了??

代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-23 21:26:51

使用对象上的键值管道,它将将action.data对象转换为下面的数组

代码语言:javascript
复制
[{key:count, value: 9}, {key:message,value:'9 sites synced'}]

如果在上面的对象上迭代:

代码语言:javascript
复制
dataItem?.value?.message = undefined
dataItem.value = 9 and 9 sites synced

这就是你所看到的。

绑定要显示的值时,只需添加一个条件。

代码语言:javascript
复制
{{ dataItem.key === 'message' ? dataItem.value: ' '}}

还有其他的方法.我认为你现在可以根据你的要求搞清楚发生了什么,需要做什么。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66340738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档