javascript - Typescript initialize two dimensional array -
i have following class:
export class reservationinfo { public person: person; public reservation: reservation; constructor(person: person, reservation: reservation) { this.person = person; this.reservation = reservation; } } this class contains 2 custom classes.
export class person { public id: number; public personal_no: number; public first_name: string; public last_name: string; public email: string; public gender: string; public address: string; public birthdate: date; public phone: string; } export class reservation { public id: number; public create_date: date; public update_date: date; public personal_no: number; public status_id: string; public payment_status_id: string; public payment_type: string; public comment: string; public res_type: string; public reservationdetail: array<reservationdetail>; } reservation class contains reservationdetail class which's have array list type of reservationperson.
export class reservationdetail { public id: number; public reservation_id: number; public create_date: date; public update_date: date; public room_id: number; public status_id: string; public start_date: date; public end_date: date; public payment_type: string; public adult: string; public child: string; public additional_bed: string; public payment_status: string; public category_id: number; public category_name: string; public extra_person: string; public reservationperson: array<reservationperson>; public reservationservice: array<reservationservices>; constructor(id: number, reservation_id: number, create_date: date, update_date: date, status_id: string, room_id: number, start_date: date, end_date: date, category_id: number, reservationperson: array<reservationperson>, reservationservice: array<reservationservices>) { this.id = id; this.reservation_id = reservation_id; this.create_date = create_date; this.update_date = update_date; this.status_id = status_id; this.room_id = room_id; this.start_date = start_date; this.end_date = end_date; this.category_id = category_id; this.reservationperson = reservationperson; this.reservationservice = reservationservice; } } this reservationperson class it's constuctor.
export class reservationperson { public reservation_id: number; public person_id: string; public first_name: string; public last_name: string; constructor(person_id: string, first_name: string, last_name: string) { this.person_id = person_id; this.first_name = first_name; this.last_name = last_name; } } i have initialisation promlem.
when try create reservationifo class instance using following code,reservationperson property null.
new reservationinfo(new person(null, null, '', '', '', '', '', new date(), ''), new reservation(null, null, null, null, null, [ new reservationdetail(null, null, null, null, null, null, null, null, null, [new reservationperson('a', 'b', 'c')], [new reservationservices(null, 'a', 'b', 'v', 'dv')]) ])); when try following code second element reservationperson not null.
new reservationinfo(new person(null, null, '', '', '', '', '', new date(), ''), new reservation(null, null, null, null, null, [ new reservationdetail(null, null, null, null, null, null, null, null, null, [new reservationperson('a', 'b', 'c')], [new reservationservices(null, 'a', 'b', 'v', 'dv')]), new reservationdetail(null, null, null, null, null, null, null, null, null, [new reservationperson('a', 'b', 'c')], [new reservationservices(null, 'a', 'b', 'v', 'dv')]) ])); i think have 0 index element problem.
you need add parameters classes initialize way initializing.
to create person object using syntax using new person(null, null, '', '', '', '', '', new date(), '') add properties parameter properties:
export class person { constructor( public id: number, public personal_no: number, public first_name: string, public last_name: string, public email: string, public gender: string, public address: string, public birthdate: date, public phone: string ) { } }
Comments
Post a Comment