首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在角度9不重复的情况下显示数据阵列?

如何在角度9不重复的情况下显示数据阵列?
EN

Stack Overflow用户
提问于 2020-10-12 06:46:23
回答 1查看 109关注 0票数 0

Html文件:

代码语言:javascript
运行
复制
   // First Table has array data --> name,netCash,phonePay2,card,cellPay2,total2 
   <table class="table table-hover table-bordered table-striped table-sm">
    <thead class="table-primary">
        <tr>
            <th class="th-sm">Collection</th>
            <th class="th-sm" *ngFor="let data of recObj">{{data?.name }}</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th class="th-sm">Cash</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.netCash | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Fone Pay</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.phonePay2 | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Card</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.card | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Cell Pay</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.cellPay2 | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Total</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.total2 | number : '.2-2'}}</td>
        </tr>
    </tbody>
</table>

// Second Table has array data --> trnUser,cashSales,fonePay,cardSales,cellPay,netSales 
<table class="table table-hover table-bordered table-striped table-sm">
    <thead class="table-primary">
        <tr>
            <th class="th-sm">Collection</th>
            <th class="th-sm" *ngFor="let data of recObj">{{data?.trnUser }}</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th class="th-sm">Cash</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.cashSales | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Fone Pay</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.fonePay | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Card</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.cardSales | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Cell Pay</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.cellPay | number : '.2-2'}}</td>
        </tr>
        <tr>
            <th class="th-sm">Total</th>
            <td class="th-sm" *ngFor="let data of recObj">
                {{data?.netSales | number : '.2-2'}}</td>
        </tr>
    </tbody>
</table>

Ts文件:

代码语言:javascript
运行
复制
getSalesData() {
console.log(this.cnvForm.value);
this.salesService.getSalesCollectionVariance(this.cnvForm.value).subscribe(data => {
  this.recObj = data;   // array data is in recObj ie. Users, TrnMode, Net amount
  console.log(this.recObj);
  this.users =this.recObj.map(function(item)  // array of Users
  {
    console.log(this.users);
    return item.user
  });
  let trnmodes =this.recObj.map(function(item)   // array of TrnMode
  {
    console.log(trnmodes);
    return item.trnmode
  });

  let netamounts =this.recObj.map(function(item)  // array of Net amount
  {
    console.log(netamounts);
    return item.netamnt
  });
});    

}

阵列数据:

代码语言:javascript
运行
复制
(2) [{…}, {…}]
  0:
    card: "1631.00"
    cardSales: "1631.00"
    cashSales: "41097.00"
    cellPay: ""
    cellPay2: ""
    div: "BAN"
    division: "BAN"
    fonePay: "0.00"
    name: "prabina"
    netCash: "41097.00"
    netSales: "42728.000000000000"
    phonePay2: "0.00"
    postDateTime: "03/12/20 12:00:00 AM"
    total2: "42728.000000000000"
    trnDate: "03/12/20 12:00:00 AM"
    trnUser: "prabina"
  1: {trnDate: "03/12/20 12:00:00 AM", division: "BAN", trnUser: "prakash", netSales: "80439.200000000000", cashSales: "65376.01", …}

阵列数据:

--这是我想在Html 中用它们各自的现金、CreditCard、QRCode显示唯一名称的数组数据。

Html视图截图

只是想以它的位置显示数据,如Html中所示。 I非常努力地解决了这个问题,但没能解决。帮我解决这个问题..谢谢你帮忙.

EN

回答 1

Stack Overflow用户

发布于 2020-10-12 07:05:30

您可以使用NgFor指令循环数据数组(https://angular.io/api/common/NgForOf)。

可能的方法如下所示:https://stackblitz.com/edit/angular-nhtmsz?file=src%2Fapp%2Fapp.component.html

编辑

我修改了Stackblitz,以包括一种可能的数据积累方法。

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

https://stackoverflow.com/questions/64312920

复制
相关文章

相似问题

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