php - ionic 2: marge details with same values -


i have array of objects database response. each object has name of course, name lecture, class,hours,day. in data base it's relationship of 1 many -> means each lecture has many lessons have table of lectures , table of times.

the times table has foreign_key of lecture_id means lectures table: lecture_id(primary_key) +more attributes. times table:id_lecture(foreign_key),id_time(primary_key) +more attributes. did query

"select * lectures,times id_lecture=lecture_id";

it works fine , give me results want. problem each lecture has lessons , want display these lessons in same ion-item , marge 1 object. in other words want that. enter image description here

that's code data

  this.coursesdata.loadlectures()         .subscribe(lecturelist=> {            console.log("getlec1");           lecturelist.foreach(lecture=>{             console.log(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           }             this.coursesa.push(newlecture);             this.coursesnames.push(lecture.course_name);             this.lecturesnames.push(lecture.name);           });           //this.courseselect=this.coursesnames[0];           this.coursesad=this.coursesa;           this.coursesnames = this.coursesnames.filter(function(elem, index, self) {                   return index == self.indexof(elem);               })              // console.log("co"+this.coursesa);                  this.loader.dismiss();                //console.log(this.lecturesnames);         // return this.coursesa;          },err=>{           console.log(err);         });   } 

as can see newlecture contains

 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           } 

but there many lessons if way it's problem because duplicate names.

i tried way shows me error

 public lectures(){   console.log("getlec");   this.courseselect='';   this.coursesnames=[];   this.lecturesnames=[];   this.coursesa=[];   this.coursesdata.loadlectures()     .subscribe(lecturelist=> {        console.log("getlec1");       lecturelist.foreach(lecture=>{         console.log(lecture);       var newlecture={             id:lecture.id_lecture,             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       }         console.log("de"+newlecture.detailshours.start_time);         if(!newlecture.id){           this.coursesa[newlecture.id]=newlecture;        // this.coursesnames.push(lecture.course_name);         //this.lecturesnames.push(lecture.name);         }         else{           this.coursesa[newlecture.id].push(newlecture);         }        });       this.coursesad=this.coursesa;        //this.courseselect=this.coursesnames[0];        console.log(this.coursesa);       /*this.coursesnames = this.coursesnames.filter(function(elem, index, self) {               return index == self.indexof(elem);           })            */           // console.log("co"+this.coursesa);             this.loader.dismiss();            console.log("lets"+this.lecturesnames);     // return this.coursesa;       },err=>{       console.log(err);     }); 

}

i got error

typeerror: cannot read property 'push' of undefined

someone has way solve it?

i think use subarrays group courses name (or course_name). instead of pushing newlecture inside coursea, push inside coursea[newlecture.name].

thus, have like:

{     "java course": [       { lecture1 },       { lecture2 }     }],     "js course": [       { lecture3 },       { lecture4 }     }] } 

then, in template do:

<ion-item ng-repeat="(key, value) in obj">     <p>{{key}}</p> <!-- example: java course -->     <div ng-repeat="(subkey, subvalue) in value">         {{subvalue}} <!-- example: lecture hours -->     </div> </ion-item> 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -