我已经从.get [{…},{…},{…},{…},{…}]中获取了JSON对象,现在我想把需要的形式传递给包含对象的数组。尝试使用foreach,但我不知道如何返回[{…},{…} ...]
hotelForms() {
return this.httpClient.get<any>(address)
.pipe(map((res) => {
return res;
}))
.catch((e: any) => Observable.throw(this.errorHandler(e)));
}
ngOnInit() {
this.calendarService.hotelForms()
.subscribe(
(res) => {
console.log(res);
res.forEach(obj => {
obj.name = name;
});
});
events: CalendarEvent[] = [
{
start: new Date('2019-04-19T03:24:00'),
Email: 'dsa@o2.pl',
end: new Date('2019-04-19T06:24:00'),
title: 'xxx',
Phone: 'xxx',
Transfer: 'xxx',
Trip: 'xxx',
PersonCount: 'xxx',
Price: 123
},
{
start: new Date('2019-04-19T19:24:00'),
end: new Date('2019-04-19T22:24:00'),
Email: 'dsa@o2.pl',
title: 'Title',
Phone: '533687183',
Transfer: 'BALICE - KRAKOW AIRPORT',
Trip: '',
PersonCount: '1-4',
Price: 123
},
];
我想实现类似的功能,但需要所有按键:
const response = {
Name: res.name || '',
start: res.tourStartTime,
end: res.tourEndTime,
title: res.title,
Email: res.email || '',
Phone: res.phone || '',
Transfer: res.transfer || '',
Trip: res.tour || '',
PersonCount: res.personCount,
Price: res.price + 'zł'
};