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

I had create a class get set, but debug show that the v have an object type, how to assign the object into the property? any idea?

jfriend00
  • 683,504
  • 96
  • 985
  • 979
Se0ng11
  • 2,303
  • 2
  • 26
  • 45

1 Answers1

1

You need to call the constructor of the class passing in the data transfer object (ajax return value) and assign the properties from the DTO to member of the class instance.

You can use something like lodash extend to do that in the class constructor so you don't need to copy over individual properties.

basarat
  • 261,912
  • 58
  • 460
  • 511