我希望在我的 ionic 2 应用程序数组中使用键和对象值。例如:
var newLecture={
name:lecture.name,
email:lecture.email,
phone:lecture.phone ,
lesson_type:lecture.lesson_type ,
detailsHours:{
'start_time':lecture.start_time,
'end_time':lecture.end_time,
'class':lecture.class,
'day':lecture.day},
details:lecture.details,
course_name:lecture.course_name
}
并且我想遍历课程newLecture
并向每个课程推送一个对象,除非具有相同的 id_course,然后我只想将新值推details_hours
送到该课程的newLecture
.
course_id 是我数据库中的主键。我有数据库包括两个表:课程和时间。每门课程都有很多次。所以当我从 db 获取它时,如果我有相同的 course_id,我想将详细信息推送到同一个键
this.coursesData.LoadLectures()
.subscribe(LectureList=> {
LectureList.forEach(lecture=>{
var newLecture={
name:lecture.name,
email:lecture.email,
phone:lecture.phone ,
lesson_type:lecture.lesson_type ,
detailsHours:{
'start_time':lecture.start_time,
'end_time':lecture.end_time,
'class':lecture.class,
'day':lecture.day},
details:lecture.details,
course_name:lecture.course_name
}
/*here i want to do something like:
` if(id_course==" `
to the same course i have already push into courseA)
so to push only the detailsHours to the object.
because what i want to do each course has many lessons.*/
this.coursesA.push(newLecture);
this.coursesNames.push(lecture.course_name);
this.LecturesNames.push(lecture.name);
});
this.coursesAD=this.coursesA;
this.coursesNames = this.coursesNames.filter(function(elem, index, self) {
return index == self.indexOf(elem);
})
this.loader.dismiss();
},err=>{
console.log(err);
});
}
如果我在 courseA 数组中已经有 java 课程,那么我只想将详细信息推送给它