Skip to content

Conversation

@movitto
Copy link

@movitto movitto commented Jun 19, 2020

When called, these will walk down the renderjson DOM structure and invoke 'show' and 'hide' on all the appropriate elements.

Use like so:

const rj = renderjson({ js : 'on })
document.getElementById("test").appendChild(rj);

rj.show_all();
rj.hide_all();
// ^ wire these up to a button click, etc

When called, these will walk down the renderjson DOM structure and
invoke 'show' and 'hide' on all the appropriate elements.

Use like so:

const rj = renderjson({ js : 'on })
document.getElementById("test").appendChild(rj);

rj.show_all();
rj.hide_all();
// ^ wire these up to a button click, etc
a.onclick = function(e) { callback(); if (e) e.stopPropagation(); return false; };
return a; };

var walkDOM = function(node, func){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting function, and use case. But not all json object graphs are tree. We explicitly, turn the tree back into a graph (for complex DTO object graphs and json schema), before rendering them.
https://github.com/andifreed/renderjson/blob/50a85654206671137e397d9d92996a94f4e9b06a/resolvejson.js

But there may be other graphs passed to this renderer, you can make it impervious to such infinite recursion by adding a array|stack parameter and checking that the object hasn't been seen yet before descending. Besure to put before descending and pop after returning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants