The length of the array in the object does not match

I am trying to use tree hierarchy in D3 and am stuck. I thought I was building JSON correctly, but when I looked at the object in the Developer Tool, I saw the following:

chrome

Note that the first line shows that the array of dependents has a length of 0, but when expanded, you can clearly see that the dependents have 3 objects. When I convert it, I get the following:

{"attributes":{"id":0,"name":"root"},"dependents":[]} 

Any ideas what could be wrong? Thank!

+5
source share
1 answer

This problem usually occurs when you change an object after registering it, because Chrome does not perform a deep copy of the object when registering, but simply saves the link.

, , .

, , :

console.log(JSON.parse(JSON.stringify(myobject)));

, , . , JSON.prune.log.

, , ...

+6

All Articles