【发布时间】:2021-03-31 14:51:53
【问题描述】:
我正在尝试使用 Ionic 进行应用程序,但我收到此错误 Cannot set property 'matricule' of undefined
我不知道我在代码中缺少什么
当我想将数据添加到此表 employeeL 时,我收到此错误
我尝试做很多改变,但问题是一样的
当表格为空时我想访问 HTML 元素的问题 (问题在于同步,因为我正在从数据库中调用数据)
请帮忙,
这是代码 HTML:
<table class="table">
<tr>
<th>مجموع</th>
<th>تم</th>
<th>مثبت</th>
<th>الاسم و اللقب</th>
<th>عون الجرد</th>
</tr>
<tr *ngFor="let item of employeeL">
<td (click)="getuserInfo(item?.matricule)">{{item?.mustBeDone}}</td>
<td (click)="getuserInfo(item?.matricule)">{{item?.done}}</td>
<td>
<ion-checkbox slot="end" checked="{{item?.status}}"></ion-checkbox>
</td>
<td (click)="getuserInfo(item?.matricule)">{{item?.fullname}}</td>
<td (click)="getuserInfo(item?.matricule)">{{item?.matricule}}</td>
</tr>
</table>
这里是 ts 文件:
employeeL:Array<Awinjard> = [];
inv_agentTab: Array<Inv_agent> = [];
drafbiesTab: Array<Drafbies> = [];
nameemployee: string = "";
inv_agentNombre: number = 0;
matriculeTable: Array<number> = [];
nameTable: Array<string> = [];
validatationTable: Array<number> = [];
ngOnInit() {
this.folder = this.activatedRoute.snapshot.paramMap.get('id');
this.awinjard.getAwinjardMatricule().subscribe(res => {
this.inv_agentTab = res as Array<Inv_agent>
this.inv_agentTab.forEach(element => {
this.matriculeTable[this.inv_agentNombre] = element.AGENT;
this.validatationTable[this.inv_agentNombre] = element.VLD;
this.inv_agentNombre++;
this.awinjard.getAwinjardNameAr().subscribe(res2 => {
this.drafbiesTab = res2 as Array<Drafbies>
this.drafbiesTab=this.drafbiesTab.filter((employee)=>employee.DECAFFE==element.AGENT)
this.nameemployee = this.drafbiesTab[0].AR_DELAFFE;
console.log(this.drafbiesTab[0].AR_DELAFFE);
this.nameTable.push(this.nameemployee);
})
});
for (let i = 0; i <= 5; i++){
//those elements that got me the error
this.employeeL[i].matricule = this.matriculeTable[i];
this.employeeL[i].fullname = this.nameTable[i];
}
})
}
界面
export interface Awinjard {
matricule: number,
fullname:string ,
status: boolean,
done: number,
mustBeDone: number,
}
【问题讨论】:
-
可能是这一行:this.employeeL[i].matricule
-
您将值放在employeeL 数组的什么位置?
-
问题出在
for的ts 文件中,我将数据放入employeeL 中