Angular:使用查找来检索名称属性不起作用

时间:2019-07-16 14:15:59

标签: json angular

我有以下按角度的服务调用,该服务返回具有以下json格式的对象FundStrategies。我基本上需要根据匹配的id字段提取名称。当我在this.SelectedFundStrategy上执行console.log时,我不确定。有人可以告诉我问题是什么吗?它正在通过console.log正确打印this.ManagerStrategyId的值

this.SelectedFundStrategy = data.FundStrategies.find(x => x.Id === this.ManagerStrategyId);

JSON

[
  {
    "Id": 243100,
    "Name": "2020 Bulkers - Titan",
    "SortOrder": null
  },
  {
    "Id": 7209,
    "Name": "A.R.T. International Strategy",
    "SortOrder": null
  },
  {
    "Id": 241951,
    "Name": "Adient - Blue Harbour",
    "SortOrder": null
  },
  {
    "Id": 300026,
    "Name": "Distressed - GoldenTree",
    "SortOrder": null
  }
]

组件

@Input() ManagerStrategyId: number;
SelectedFundStrategy: any;

public getFundDetails(selectedFundId: number, refresh: boolean = true) {
        if(refresh) 
            this.FundDetails = null;

        this.Loading = true;
        this.EditMode = false;
        this.IsInsertMode = false;

        if (!selectedFundId) {
            selectedFundId = -1;
        }
            this.fundService.getFundDetails(selectedFundId).subscribe((data: any) => {
                this.FundDetails = data;
                this.FundStrategies = data.FundStrategies;
                this.SelectedFundStrategy = data.FundStrategies.find(x => x.Id === this.ManagerStrategyId);
                console.log(this.SelectedFundStrategy);


                this.SelectedFundId = this.FundDetails.FundId;
                this.vehicleTypeChanged(this.FundDetails.VehicleTypeId);
                this.changeDetectorRef.markForCheck();
                this.Loading = false;

                if(this.FundDetails.FundId === 0){
                    this.EditMode = true;
                    this.IsInsertMode = true;
                }
            });
    }

0 个答案:

没有答案