简体   繁体   English

如何在角度 9 中显示数据数组而不重复?

[英]How to display data array without duplication in angular 9?

Html file: html文件:

   // 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 File: Ts文件:

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
  });
});    

} }

Array data:数组数据:

(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", …}

Array Data: [![Console data I am getting this data in console in angular.数组数据: [![控制台数据我在控制台中以角度获取此数据。 It is same data as Array data in above --> Sql server data][1]][1]它与上面的数组数据相同的数据 --> Sql server data][1]][1] 我在控制台中获取此数据 --> Sql 服务器数据

This is the array data that i want to display unique name with their respective Cash, CreditCard, QRCode in Html page这是我想在 Html 页面中使用各自的现金、信用卡、二维码显示唯一名称的数组数据

Html view [Screenshoot] [![enter image description here][3]][3] Html 视图 [屏幕截图] [![在此处输入图片描述][3]][3]

Just want to display data in its position as shown in Html view [Screenshoot].只想在 Html 视图 [屏幕截图] 中显示的位置显示数据。 I tried so hard to resolve this problem but could not.. Help me to solve this problem.. Thank you For helping hand...我很努力地解决这个问题,但不能..帮我解决这个问题..谢谢你的帮助...

You can use the NgFor directive to loop over your data array ( https://angular.io/api/common/NgForOf ).您可以使用 NgFor 指令循环遍历您的数据数组 ( https://angular.io/api/common/NgForOf )。

A possible approach could look like this example here: https://stackblitz.com/edit/angular-nhtmsz?file=src%2Fapp%2Fapp.component.html一种可能的方法可能类似于这里的示例: https : //stackblitz.com/edit/angular-nhtmsz?file=src%2Fapp%2Fapp.component.html

EDIT编辑

I revised the Stackblitz to include a possible approach for the data accumulation.我修改了 Stackblitz 以包含一种可能的数据积累方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM