2017-09-01 99 views
1

我正在努力处理如何处理来自打字稿中VSTS API的响应。来自REST API的复杂响应的Typescript接口

有没有办法处理这个接口?

export interface Fields { 
'System.AreaPath': any; 

'System.TeamProject': string; 
'System.IterationPath': string; 
'System.WorkItemType': string; 
'System.State': string; 
'System.Reason': string; 
'System.AssignedTo': string; 
'System.CreatedDate': Date; 
'System.CreatedBy': string; 
'System.ChangedDate': Date; 
'System.ChangedBy': string; 
'System.Title': string; 
'Microsoft.VSTS.Feedback.ApplicationType': string; 
'System.Description': string; 
'System.History': string; 
'Microsoft.VSTS.Feedback.ApplicationStartInformation': string; 
'Microsoft.VSTS.Feedback.ApplicationLaunchInstructions': string; 
} 

在我的代码我试图环出字段(工作项===字段)

 <tbody> 
     <tr *ngFor="let workitem of workItems"> 
      <!-- *ngFor="let field of workitems.fields" --> 
      <td>{{workitem.fields.System.AreaPath}} << THIS IS NOT ALLOWED</td> 
     </tr> 

     </tbody> 

任何一个得到了一个绝妙的主意如何解决这个问题?

+0

item.fields [ 'name.with.dots'] –

回答

1

首先,你不能在一个对象上使用ngFor。

其次,如果workItem的类型为Fields,则不需要任何循环来显示其属性之一。所有你需要的,就像在JavaScript或打字稿,是

workItems['System.AreaPath'] 
+1

你提到的ngFor部分有注释 –

+0

@ Jota.Toledo不,它不是。我引用:“workItems === Fields”[...] “ –

+0

你说得对,但仍不清楚什么样的数据类型是workItems,我想op应该更新他的题。 –

3

{{ workitem.fields['System.AreaPath'] }}

的作品?

+0

这应该是的 – Swoox

+0

是它的工作原理!谢谢!!! – MrWeiland

0

感谢@elzoy和@JB Nizet它是[“System.AreaPath”]我在需要时打开接口属性是“复杂”。我真的错过了类似于c#[JsonProperty]之类的打字机中的一些装饰器。但是,这很好。

很多感谢 - 在你帮助我之前浪费了几个小时。 :)

 <tbody> 
     <tr *ngFor="let workitem of workItems"> 

      <td>{{workitem.fields['System.AreaPath']}}</td> 
     </tr> 
     </tbody> 


export interface Fields { 

'System.AreaPath': string; 

'System.TeamProject': string; 
'System.IterationPath': string; 
'System.WorkItemType': string; 
'System.State': string; 
'System.Reason': string; 
'System.AssignedTo': string; 
'System.CreatedDate': Date; 
'System.CreatedBy': string; 
'System.ChangedDate': Date; 
'System.ChangedBy': string; 
'System.Title': string; 
'Microsoft.VSTS.Feedback.ApplicationType': string; 
'System.Description': string; 
'System.History': string; 
'Microsoft.VSTS.Feedback.ApplicationStartInformation': string; 
'Microsoft.VSTS.Feedback.ApplicationLaunchInstructions': string; 
} 

export interface WorkItemFullInformation { 
id: number; 
rev: number; 
fields: Fields; 
url: string; 

}

export interface FetchWorkItemRootObject { 
count: number; 
value: WorkItemFullInformation[]; 

}