I have the following classes:
class Term {
constructor(id, title, snippets){
this.id = id
this.title = title
this.snippets = snippets
}
}
class Snippet {
constructor(id, text) {
this.id = id
this.text = text
}
}
And I have a JSON object such as:
[{
"id": 1,
"title": "response",
"snippets": [{
"id": 2,
"text": "My response"
}, {
"id": 3,
"text": "My other response"
}]
}]
I'm able to create a new Term object as follows:
let term = Object.assign(new Term, result[0])
However, the snippets
property does not create Snippet
objects from this. What's the best way to do that?