我越來越ngFor嵌套問題,它顯示'不能讀取未定義的屬性'字段。Angular 2:ngFor嵌套問題
我試過提及其他問題,但無法得到它。請幫助我如何使數據正確
// service call
this.xmldataService.getReport().subscribe(
(report) => {
this.group = report.CrystalReport.Group;
});
// Error
ERROR TypeError: Cannot read property 'Field' of undefined
at Object.eval [as updateDirectives] (AppComponent.html:23)
at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:12641)
at checkAndUpdateView (core.es5.js:12053)
at callViewAction (core.es5.js:12367)
at execEmbeddedViewsAction (core.es5.js:12339)
at checkAndUpdateView (core.es5.js:12054)
at callViewAction (core.es5.js:12367)
at execComponentViewsAction (core.es5.js:12313)
at checkAndUpdateView (core.es5.js:12059)
at callWithDebugContext (core.es5.js:13041)
<table class="table table-bordered" *ngFor="let head of group; let i = index">
<thead>
<tr>
<th *ngFor="let d of head.GroupHeader.Section.Text; let i = index">{{d.TextValue}}</th>
</tr>
</thead>
<tbody>
<tr>
<td *ngFor="let d of head.Details.Section.Field; let i = index">{{d.value}}</td>
</tr>
</tbody>
</table>
是我的JSON,我得到錯誤
{
\t "@Level": "2",
\t "Section": {
\t \t "@SectionNumber": "0",
\t \t "Field": [{
\t \t \t "@Name": "GroupNameTEAMNO1",
\t \t \t "@FieldName": "GroupName ({PDA112P.TEAM_NO})",
\t \t \t "FormattedValue": "DL04",
\t \t \t "Value": "DL04"
\t \t }, {
\t \t \t "@Name": "ASMPROCNO1",
\t \t \t "@FieldName": "{PDA112P.ASM_PROC_NO}",
\t \t \t "FormattedValue": "3H878",
\t \t \t "Value": "3H878"
\t \t }, {
\t \t \t "@Name": "UNITNO1",
\t \t \t "@FieldName": "{PDA112P.UNIT_NO}",
\t \t \t "FormattedValue": "H83937",
\t \t \t "Value": "H83937"
\t \t }, {
\t \t \t "@Name": "APPROVEDDATE1",
\t \t \t "@FieldName": "{PDA112P.APPROVED_DATE}",
\t \t \t "FormattedValue": null,
\t \t \t "Value": null
\t \t }, {
\t \t \t "@Name": "REJECTEDDATE1",
\t \t \t "@FieldName": "{PDA112P.REJECTED_DATE}",
\t \t \t "FormattedValue": null,
\t \t \t "Value": null
\t \t }, {
\t \t \t "@Name": "MAINTDATE1",
\t \t \t "@FieldName": "{PDA112P.MAINT_DATE}",
\t \t \t "FormattedValue": "04/20/2017",
\t \t \t "Value": "04/20/2017"
\t \t }, {
\t \t \t "@Name": "RESNFORCHANGE1",
\t \t \t "@FieldName": "{PDA112P.RESN_FOR_CHANGE}",
\t \t \t "FormattedValue": "CHANGED GET TO GRASP IN WORKING POINT DETAIL NO PCF REQUIRED",
\t \t \t "Value": "CHANGED GET TO GRASP IN WORKING POINT DETAIL NO PCF REQUIRED"
\t \t }, {
\t \t \t "@Name": "ISSUEDDATE1",
\t \t \t "@FieldName": "{PDA112P.ISSUED_DATE}",
\t \t \t "FormattedValue": null,
\t \t \t "Value": null
\t \t }]
\t }
}
是組標籤
輸出{"@Level":"1","GroupHeader":{"Section":{"@SectionNumber":"0","Text":[{"@Name":"Text16","TextValue":"Team"},{"@Name":"Text17","TextValue":"Process"},{"@Name":"Text18","TextValue":"Unit"},{"@Name":"Text19","TextValue":"Maint.\n\nDate"},{"@Name":"Text21","TextValue":"Unit Rank /\n\nQuality Issues"},{"@Name":"Text20","TextValue":"Description of Change"},{"@Name":"Text22","TextValue":"Issued \n\nDate"},{"@Name":"Text24","TextValue":"Rejected\n\nDate"},{"@Name":"Text23","TextValue":"Approved\n\nDate"}]}},"Details":{"@Level":"2","Section":{"@SectionNumber":"0","Field":[{"@Name":"GroupNameTEAMNO1","@FieldName":"GroupName ({PDA112P.TEAM_NO})","FormattedValue":"DL04","Value":"DL04"},{"@Name":"ASMPROCNO1","@FieldName":"{PDA112P.ASM_PROC_NO}","FormattedValue":"3H878","Value":"3H878"},{"@Name":"UNITNO1","@FieldName":"{PDA112P.UNIT_NO}","FormattedValue":"H83937","Value":"H83937"},{"@Name":"APPROVEDDATE1","@FieldName":"{PDA112P.APPROVED_DATE}","FormattedValue":null,"Value":null},{"@Name":"REJECTEDDATE1","@FieldName":"{PDA112P.REJECTED_DATE}","FormattedValue":null,"Value":null},{"@Name":"MAINTDATE1","@FieldName":"{PDA112P.MAINT_DATE}","FormattedValue":"04/20/2017","Value":"04/20/2017"},{"@Name":"RESNFORCHANGE1","@FieldName":"{PDA112P.RESN_FOR_CHANGE}","FormattedValue":"CHANGED GET TO GRASP IN WORKING POINT DETAIL NO PCF REQUIRED","Value":"CHANGED GET TO GRASP IN WORKING POINT DETAIL NO PCF REQUIRED"},{"@Name":"ISSUEDDATE1","@FieldName":"{PDA112P.ISSUED_DATE}","FormattedValue":null,"Value":null}]}}}
你可以給你的數據結構/模型的更多細節?例如組?頭? – sugarme
添加了json供您參考 –
如果您輸入「service call」,console.log(this.group)的輸出如何?我的意思是,如果您添加爲: this.xmldataService.getReport()。subscribe( (report)=> { this.group = report.CrystalReport.Group; console.log(this.group); }); – sugarme