0

i'm looking to make in my ionic 2 app array with key and object values. For example:

 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
      }

and i want to loop through the courses and push an object of newLecture to each, except when have the same id_course, then I only want to push the new values in details_hours into that course's newLecture. course_id is primary key from my db. i have db include two tables: Courses and Times. each course has many times. so when i get it from db, if i have the same course_id i want to push the details to the same key

 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);
    });

}

in the right side with draw, it's what i want to do exactly. enter image description here

if i have java course already in courseA array so i just want to push the details hours to it

Manspof
  • 598
  • 26
  • 81
  • 173
  • please elaborate more, specify your question explicitly and add `typescipt` as a tag so we can see syntax highlighting. – Nate May Nov 12 '16 at 19:57
  • @NateMay i edited my post. – Manspof Nov 12 '16 at 20:06
  • Where is the course_id? I'm not sure how to access it. – Nate May Nov 12 '16 at 20:44
  • course_id is primary key from my db. i have db include two tables: Courses and Times. each course has many times. so when i get it from db, if i have the same course_id i want to push the details to the same key . you get me? – Manspof Nov 12 '16 at 20:48

0 Answers0