Я отображаю список сведений о студентах из базы данных на основе выбранной категории.Мне нужно хранить эти данные в массиве и многократно хранить все данные (все данные о студентах) в базе данных.
home.html
<ion-list>
<!-- Select Stream -->
<ion-item>
<ion-label>Stream:</ion-label>
<ion-select [(ngModel)]="streamId" (ionChange)="selectedStream(id)" class="optionsStyle" placeholder="Select Stream">
<ion-option *ngFor="let list of getListStream" value="{{list.Stream_Id}}">{{list.Stream_Name}}</ion-option>
</ion-select>
</ion-item>
<!-- Select Medium -->
<ion-item>
<ion-label>Medium:</ion-label>
<ion-select [(ngModel)]="mediumId" (ionChange)="selectedMedium(id)" class="optionsStyle" placeholder="Select">
<ion-option *ngFor="let list of getListMedium" value="{{list.Medium_Id}}">{{list.Medium_Name}}</ion-option>
</ion-select>
</ion-item>
<!-- Select Standard -->
<ion-item>
<ion-label>Standard:</ion-label>
<ion-select [(ngModel)]="standardId" (ionChange)="selectedStandard(id)" class="optionsStyle" placeholder="Select">
<ion-option *ngFor="let list of getListStandard" value="{{list.Standard_Id}}">{{list.Standard_Name}}</ion-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label>Section:</ion-label>
<ion-select [(ngModel)]="sectionId" (ionChange)="selectedSection(id)" class="optionsStyle" placeholder="Select">
<ion-option *ngFor="let list of getListSection" value="{{list.Section_Id}}">{{list.Section_Name}}</ion-option>
</ion-select>
</ion-item>
<ion-item *ngFor="let list of getStudentList">
<ion-label>{{list.Student_FirstName}}</ion-label>
<ion-toggle [(ngModel)]="list.Student_LastName" (ionChange)="changeToggle(list)"></ion-toggle>
</ion-item>
<button ion-button full *ngIf="getStudentList" (click)="sendAttendanceStstus(getStudentList)">Submit</button>
</ion-list>
home.ts
constructor
(
public nvCtrl: NavController,
private restAttendance: RestAttendanceProvider,
public alertCtrl: AlertController
) { }
ionViewDidEnter() {
this.restAttendance.getStudentAttendanceStreamDetails()
.then(data => {
this.getListStream = data;
console.log(this.getListStream);
});
}
//Stream Id
selectedStream(id) {
console.log(this.streamId);
id = this.streamId;
this.restAttendance.getStudentAttendanceMediumDetails(this.streamId)
.then(data => {
this.getListMedium = data;
console.log(this.getListMedium);
});
}
//MediumId
selectedMedium(id) {
console.log(this.streamId + this.mediumId);
id = this.mediumId;
this.restAttendance.getStudentAttendanceStandardDetails(this.streamId, this.mediumId)
.then(data => {
this.getListStandard = data;
console.log(this.getListStandard);
});
}
//StandardId
selectedStandard(id) {
console.log(this.standardId);
id = this.standardId;
this.restAttendance.getStudentAttendanceSectionDetails(this.streamId, this.mediumId, this.standardId)
.then(data => {
this.getListSection = data;
console.log(this.getListSection);
});
}
//SectionId
selectedSection(id) {
console.log(this.sectionId);
id = this.sectionId;
this.restAttendance.getStudentAttendanceList(this.streamId, this.mediumId, this.standardId, this.sectionId)
.then(data => {
this.getStudentList = data;
console.log(this.getStudentList);
});
}
changeToggle(list) {
console.log(list.Student_Id + list.Student_LastName);
}
sendAttendanceStstus(getStudentList) {
if (!this.streamId || !this.mediumId || !this.standardId || !this.sectionId) {
let alert = this.alertCtrl.create({
title: "Select",
subTitle: "please select all details",
buttons: ['ok']
}).present();
console.log("Select details");
} else {
console.log('StreamId: '+ this.streamId + ' mediumId: ' + this.mediumId + ' StandardId: ' + this.standardId + ' SectionId: ' + this.sectionId + ' '+getStudentList);
// this.restAttendance.postStudentAttendanceDetails(this.streamId, this.mediumId, this.standardId, this.sectionId, this.studentId, this.Student_Name)
// .then(data => {
// console.log(data);
// this.nvCtrl.push(DashboardPage);
// }).catch(err => {
// console.log(err);
// });
}
}
поставщик
getStudentAttendanceList(streamId, mediumId, standardId, sectionId) {
return new Promise(resolve => {
this.http.get(this.apiStudentList+'?StreamId='+streamId+'&MediumId='+mediumId+'&StandardId='+standardId+'&SectionId='+sectionId).subscribe(data => {
resolve(data);
console.log(data);
}, err => {
console.log(err);
});
});
}
postStudentAttendanceDetails(streamId, mediumId, standardId, sectionId, id, name) {
return new Promise(resolve => {
this.http.post('http://localhost:49379/api/Attendance/PostStudentAttendance', {
"Student_Id": id,
"Student_Name": name,
"Attendance_Status": 1,
"section_Id": '10',
"Date": 15/10/2018
}).subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
Мне нужно, чтобы каждое значение переключателя в отношении идентификатора студента сохранялось в переменной и отправлялось в базу данных каждого студента в списке.