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?
Term, e.g.fromJSON, that parses the JSON, createsSnippetsinstances and passes them tonew Termalong with the other parameters. There is no automagical way to do that.