2014-04-26 6 views
0
class ClassList 
{ 
    private _workDate: string = null; 
    private _fromTime: string = null; 
    private _toTime: string = null; 
    private _roomId: string = null; 
    private _slotId: string = null; 

    constructor() { 

    } 

    public get WorkDate(): string { 
     return this._workDate; 
    } 

    public set WorkDate(value: string) { 
     this._workDate = value; 
    } 

    public get FromTime(): string { 
     return this._fromTime; 
    } 

    public set FromTime(value: string) { 
     this._fromTime = value; 
    } 


    public get ToTime(): string { 
     return this._toTime; 
    } 

    public set ToTime(value: string) { 
     this._toTime = value; 
    } 


    public get RoomId(): string { 
     return this._roomId; 
    } 

    public set RoomId(value: string) { 
     this._roomId = value; 
    } 


    public get SlotId(): string { 
     return this._slotId; 
    } 

    public set SlotId(value: string) { 
     this._slotId = value; 
    } 
} 


$(data).each(function (i, v) { 
       v=> ClassList; 
       console.log(v); 
} 

클래스를 생성했지만 디버그에 v가 객체 유형을 가지고 있는지, 속성에 객체를 할당하는 방법이 있습니까? 어떤 생각?Typescript ajax 객체를 속성에 할당하는 방법은 무엇입니까?

+0

감사합니다. 정보를 제공해 주셔서 감사합니다. – Se0ng11

답변

1

데이터 전송 객체 (ajax 반환 값)를 전달하는 클래스의 생성자를 호출하고 DTO의 속성을 클래스 인스턴스의 멤버에 할당해야합니다.

클래스 생성자에서 lodash extend와 같은 것을 사용할 수 있으므로 개별 속성을 복사 할 필요가 없습니다.

관련 문제