Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'show_all', 'hide_all' methods on top level renderjson element #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
@@ -97,17 +97,26 @@ var module, window, define, renderjson=(function() {
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