Javascript 从http响应中乘以并添加json格式的值

Javascript 从http响应中乘以并添加json格式的值,javascript,html,angular,Javascript,Html,Angular,我使用下面的代码调用一个API,该API根据需要返回数据 search() { this.apiService.getResults() .subscribe( response => { console.log(response.data); this.data = response.data } }, err => { } ); } 响应的结构如

我使用下面的代码调用一个API,该API根据需要返回数据

search() {
    this.apiService.getResults()
    .subscribe(
      response => {
          console.log(response.data);
          this.data = response.data
        }
      },
      err => {
      }
    );

  }
响应的结构如下所示

this.data = [{name:Corn Flakes, price: 40, quantity: 20, name: 'Oats', price: 32, quantity: 23, name: 'Springles', price: 3, quantity: 88}]
看法


{{i+1}}
{{item.name}
{{item.price}}
{{item.quantity}
{{item.price*item.quantity}货币:'GHc':'code'}
总数=
我能够计算每一行的小计。
我想在视图中实现的是计算价格和数量,以了解组件中所有项目的总和,解决异步调用后,您可以使用
Array.prototype.reduce
累积如下所示的总数,然后向组件类添加一个新字段
total
,以显示在视图中

const data=[{名称:'Corn Flakes',价格:40,数量:20,名称:'Oats',价格:32,数量:23,名称:'Springles',价格:3,数量:88}];
const total=data.reduce((总和,{price,quantity})=>sum+=price*quantity,0);

控制台日志(总计)问题是什么?
    <tr *ngFor="let item of searchResults; let i = index"
                class="table-row" #row>
              <td>
                {{i + 1}}
              </td>
              <td>
                {{item.name}}
              </td>
              <td>
                {{item.price}}
              </td>
              <td>
                  {{item.quantity}}
              </td>
              <td>
                {{item.price * item.quantity | currency:'GHc ':'code'}}
              </td>
            </tr>

Overall Total =