简体   繁体   English

错误TS:2339类型{}上没有属性“ Project”

[英]error TS: 2339 Property “Project” does not exist on type { }

I am using crossfilter js library in my Angular 2 + project, As per documentation of crossfilter, Crossfilter API accepts array of javascript objects. 我在Angular 2 +项目中使用crossfilter js库,根据crossfilter的文档,Crossfilter API接受javascript对象数组。 Using a service I am getting data from mongo db, using observable I am getting data in form of array of Object. 使用服务,我从mongo db获取数据,使用可观察的我以Object数组的形式获取数据。

below is service call in my component 下面是我组件中的服务呼叫

this._getdataservice.getData().subscribe(  
    function (posts) {
        console.log(posts);
        var ndx = crossfilter(posts);
        var projectDim = ndx.dimension(function(d) { return d.Project });
    }
)

I am Getting error as shown in below screen shot 我遇到如下屏幕截图所示的错误 在此处输入图片说明

If I print post object in console it is giving array of object 如果我在控制台中打印发布对象,则给出对象数组

在此处输入图片说明

Code written in service 服务中编写的代码

getData(): Observable<any>  {
    return this.http.get<any>(this.url);
}

code written in component in which service is injected 在注入服务的组件中编写的代码

constructor(private _getdataservice: DataServiceService) { }

ngOnInit() { 
    this._getdataservice.getData().subscribe(function(posts){
        console.log(posts);
        var ndx = crossfilter(posts);
        var projectDim = ndx.dimension(function(d) {return d.Project});
    })
}

Please help me to understand where I am doing wrong? 请帮助我了解我在哪里做错了?

d的类型更改为any

var projectDim = ndx.dimension(function(d : any) { return d.Project};

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

相关问题 错误TS2339:类型“字符串”上不存在属性“默认”。** - Error TS2339: Property 'Default' does not exist on type 'string'.** 错误 TS2339:类型“CustomerTransfert[]”上不存在属性“num” - error TS2339: Property 'num' does not exist on type 'CustomerTransfert[]' 错误TS2339:类型“ HTMLElement”上不存在属性“ imageID” - error TS2339: Property 'imageID' does not exist on type 'HTMLElement' Typescript 错误:属性“status”在类型“never”上不存在。ts(2339) - Typescript error: Property 'status' does not exist on type 'never'.ts(2339) 错误TS2339:类型“ {}”上不存在属性“ forEach” - error TS2339: Property 'forEach' does not exist on type '{}' 错误TS2339:类型“ HTMLElement”上不存在属性“名称” - error TS2339: Property 'name' does not exist on type 'HTMLElement' 错误 TS2339:“温度”类型上不存在属性“摄氏度” - error TS2339: Property 'celsius' does not exist on type 'Temperature' 错误 TS2339:“特殊 []”类型上不存在属性“默认” - Error TS2339: Property 'default' does not exist on type 'Special[]' TS2339:类型“ {}”上不存在属性“ props” - TS2339: Property 'props' does not exist on type '{}' 属性“模块”在类型“ typeof MyEditor”上不存在。ts(2339) - Property 'modules' does not exist on type 'typeof MyEditor'.ts(2339)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM