Javascript 角度6中的贴图元素
JSONJavascript 角度6中的贴图元素,javascript,angular,Javascript,Angular,JSON let data = Array.from(yourObject).map(arrayElement => { // do stuffs with arrayElement }); 组成部分 import { Component, OnInit } from '@angular/core'; import {MonthlyViewService} from "../../../monthlyView.service"; import 'rxjs/add/operator/m
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
组成部分
import { Component, OnInit } from '@angular/core';
import {MonthlyViewService} from "../../../monthlyView.service";
import 'rxjs/add/operator/map';
@Component({
selector: 'app-calendar',
templateUrl: './calendar.component.html',
styleUrls: ['./calendar.component.css']
})
export class CalendarComponent implements OnInit {
constructor(private monthlyViewService: MonthlyViewService) {}
ngOnInit() {
this.monthlyViewService.getMonthlyData().subscribe(res => {
let data = res.map(res => res.data);
console.log(data);
})
}
}
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
在上面的代码中,我希望从响应中访问数据、日历数据并将其存储到不同的数组中。我在映射上出错-类型对象上不存在映射。
任何解决方案都认为您的对象(res)属于object类型。您可以通过打印
res
本身进行验证
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
它正确地说,map()
不存在于对象
类型上。但是,它确实存在于数组
类型上。因此,您可以执行以下()操作:
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
映射操作符将您选择的函数应用于每个项目
由源Observable发出,并返回发出
这些函数应用的结果
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
首先,从RxJs 6开始,您必须像这样导入运算符:
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
import { map } from 'rxjs/operators';
其次,您必须在映射之前使用管道
:
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
ngOnInit() {
this.monthlyViewService.getMonthlyData().subscribe(res => {
let data = res.pipe( map(res => res.data) );
console.log(data);
})
}
使用res
作为any
类型。然后,如果实际响应类型中确实存在map
,则希望您不会得到该错误
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
this.monthlyViewService.getMonthlyData().subscribe((res:any) => {
let data = res.map((res:any) => res.data);
console.log(data);
})
希望这对你有用
let data = Array.from(yourObject).map(arrayElement => {
// do stuffs with arrayElement
});
从'@angular/core'导入{Component,OnInit};
从“../../../monthlyView.service”导入{monthlyView服务}”;
从“rxjs/operators”导入{map}
;
@组成部分({
选择器:“应用程序日历”,
templateUrl:“./calendar.component.html”,
样式URL:['./calendar.component.css']
})
导出类CalendarComponent实现OnInit{
构造函数(私有monthlyViewService:monthlyViewService){}
恩戈尼尼特(){
this.monthlyViewService.getMonthlyData().subscribe(res=>{
让数据=res.pipe(映射(res=>
资源数据);
)
控制台日志(数据);
})
}
}
能否显示getMonthlyData()
方法及其返回的内容?能否控制res
?a=nd post您从中得到了什么?添加了图像并使用了u r代码段,现在它在管道上给出了错误。同一管道在类型对象上不存在