How do I initialize a TypeScript object with a JSON object

前端 未结 16 719
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 08:30

I receive a JSON object from an AJAX call to a REST server. This object has property names that match my TypeScript class (this is a follow-on to this question).

Wha

16条回答
  •  一生所求
    2020-11-22 08:51

    JQuery .extend does this for you:

    var mytsobject = new mytsobject();
    
    var newObj = {a:1,b:2};
    
    $.extend(mytsobject, newObj); //mytsobject will now contain a & b
    

提交回复
热议问题