Reputation: 463
I have code in my dashboard.component.ts, just like this:
this.scheduleService.getShiftSchedule().subscribe((temp)=>{
this.api = temp;
var ids = [['user_id', 1], ['status', 2]],
result = temp.map(o => ids.map(([key, id]) => ({ id, content: o[key] })));
this.tablePresetData = result;
})
And the import library:
import { Component, OnInit, ViewEncapsulation, ViewChild } from '@angular/core';
import { TicketService } from '../../ticket.service';
import { ScheduleService } from '../../schedule.service';
import {Chart} from 'chart.js';
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { map, filter, switchMap } from 'rxjs/operators';
Are there any mistakes i have made while writing this code? or have i just forget something?
Upvotes: 0
Views: 438
Reputation: 3387
native map
is only existing on Array. If you want to use map on an object, you can use lodash
;
so if you use lodash
import { map } from 'lodash';
result = map(temp, o => ids.map(([key, id]) => ({ id, content: o[key] })));
otherwise you must loop throught the key list of the object, like
result = Object.keys(temp).map(o => ids.map(([key, id]) => ({ id, content: temp[o][key] })));
Upvotes: 1