在我的离子应用程序中,我有一组用户,它们具有唯一的用户ID(用户数据来自http GET,选择我数据库中的所有用户),同时我的数据库中有另一个表被调用Eletroneuro,每行都有一个用户ID,所以我可以将eletroneuro行链接到每个用户,有些用户有超过1个eletroneuro行。我试图通过我的打字稿文件中的数组数组来实现这一点,但是我在浏览器中没有定义" A在执行离子服务时没有错误。
HTML PAGE
<ion-item>
<ion-label>Time</ion-label>
<ion-datetime displayFormat="DD-MM-YYYY" [(ngModel)]="data"></ion-datetime>
</ion-item>
<button ion-button (click)="mostrarTabelaPacientesDb(data)">Mostrar Fichas</button>
<div *ngFor="let user of users">
<ion-row>
<ion-col col-6>
{{user.pacientenome}}
</ion-col>
<ion-col col-6>
{{user.pacientedataexame}}
</ion-col>
</ion-row>
<ion-row>
<button ion-button (click)="mostrarEletroneuro(user.id)">Mostrar tabelas</button>
<div *ngFor="let eletro of eletroneuros">
<ion-row> {{eletro.musculonome}}</ion-row>
</div>
</ion-row>
</div>
</ion-grid>
</ion-content>
TYPESCRIPT PAGE
@IonicPage()
@Component({
selector: 'page-lista-pacientes',
templateUrl: 'lista-pacientes.html',
})
export class ListaPacientesPage {
data: any = {};
users: any[];
eletroneuro: any[];
eletroneuros: any[][];
mostrarTabela: boolean = false;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public service: ServiceProvider
)
{
}
ionViewDidLoad() {
console.log('ionViewDidLoad ListaPacientesPage');
}
mostrarTabelaPacientesDb(data: String){
for(let n of this.users) {
this.mostrarEletroneuro(n.id)
this.eletroneuros.push(this.eletroneuro);
}
this.service.getListaPacienteByData(data).subscribe(
data => this.users = data
)
}
mostrarEletroneuro(id: number){
this.mostrarTabela = true;
this.service.getDataEletroneuroById(id).subscribe(
data => this.eletroneuro = data
)
return this.eletroneuro;
}
}
SERVICE.TS相关方法
getListaPacienteByData(data: String){
return this.http.get(`${this.api}pacientesdb/${data}/`).map(res=> res.json())
}
getDataEletroneuroById(id: number){
return this.http.get(`${this.api}eletroneuro/${id}/`).map(res=> res.json())
}