【问题标题】:Typescript how to assign ajax object into property? [duplicate]打字稿如何将ajax对象分配给属性? [复制]
【发布时间】:2014-06-11 22:13:34
【问题描述】:
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);
 }

我已经创建了一个类get set,但调试显示v有一个对象类型,如何将对象分配给属性?有什么想法吗?

【问题讨论】:

  • 好的,谢谢你的信息

标签: jquery typescript


【解决方案1】:

您需要调用传入数据传输对象(ajax 返回值)的类的构造函数,并将 DTO 中的属性分配给类实例的成员。

您可以在类构造函数中使用 lodash extend 之类的东西来执行此操作,因此您无需复制单个属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2021-06-29
    • 2020-08-04
    • 2022-01-26
    • 1970-01-01
    • 2010-11-15
    相关资源
    最近更新 更多