API 호출을 통해 데이터를 얻는 asp.net 코어 백엔드가 있습니다. 이 개체 모델이 있습니다.
public class CostGroup
{
public long Id { get; set; }
public string Name { get; set; }
public int Rank { get; set; }
public bool HcPlanning { get; set; }
public bool OtherPlantCost { get; set; }
public bool DirectLabCost { get; set; }
public long CompanyId { get; set; }
public Company Company { get; set; }
}
그리고이 API 호출 :
[HttpGet("{id}")]
public CostGroup GetCostGroup(long Id)
{
return DataContext.CostGroups.Find(Id);
}
그리고 이것은 각도의 해당 서비스입니다.
getCostGroup(id: number) {
return this.http.get<CostGroup>('api/masterdata/costaccounting/costgroups/' + id);
}
모든 것이 작동하며 클라이언트 측에서 다음과 같은 결과를 얻습니다.
{"id":24,"name":"ss","rank":123,"hcPlanning":true,"otherPlantCost":true,"directLabCost":true,"companyId":1,"company":null}
보시다시피 부울 값이 올바르게 인식됩니다. 그러나 부울 값을 읽으려면 정의되지 않습니다. 나는 CostGroup
다음과 같은 각도로 객체를 읽습니다 .
this.service.getCostGroup(e.key).subscribe(costGroup => {
this.costGroup = costGroup;
this.companyId = costGroup.companyId;
this.hcplanning = costGroup.hcplanning;
this.otherplantcost = costGroup.otherplantcost;
this.directlabcost = costGroup.directlabcost;
alert(costGroup.directlabcost);
this.editMode = true;
this.name = costGroup.name;
this.popup.instance.show();
});
모든 부울 필드가 정의되지 않았습니다. 왜? 이 문제를 극복하는 방법은 무엇입니까?
개체 속성은 낙타 케이스입니다.
"otherPlantCost":true
그러나 소문자로 액세스하고 있습니다.
this.otherplantcost = costGroup.otherplantcost;
낙타 케이스에서 올바르게 액세스해야합니다.
this.otherplantcost = costGroup.otherPlantCost;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다