emmasax / json-formatter Goto Github PK
View Code? Open in Web Editor NEWTakes JSON and renders it into an HTML list.
Home Page: http://emmasax.github.io/json-formatter/
License: MIT License
Takes JSON and renders it into an HTML list.
Home Page: http://emmasax.github.io/json-formatter/
License: MIT License
Issue:
.toggle click event needs to be "scoped" to its instance's list_id setting
Description:
If more than one Instance of JSONFormatter
is used then the click event gets binded {n} times.
So, if an object is toggled it will close right after it opens.
Code Reference:
json-formatter/JSONFormatter.js
Line 142 in c150340
Reproduce:
touch test.html && vi test.html
<html>
<head>
<title>Issue x</title>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- JSONFormatter -->
<link rel="stylesheet" href="JSONFormatter.css">
<script type="text/javascript" src="JSONFormatter.js"></script>
</head>
<body>
<div class="code">{"foo": {"foo": "bar"}}</div>
<div class="code">{"foo": {"foo": "bar"}}</div>
<div class="code">{"foo": {"foo": "bar"}}</div>
<script type="text/javascript">
// fancy way to setup code
var loop = 5;
var $els = $('.code');
for (var i = 0; i <= $els.length - 1; i++ ) {
$el = $els[i];
var json = JSON.parse($el.innerText);
var ref = '.code:eq(' + $els.index($el) + ')';
$(ref).empty();
JSONFormatter.format(json, {'appendTo': ref, 'collapse': true, 'list_id': 'json_' + i});
}
</script>
</body>
</html>
open test.html
big JSON objects freezes pages.
The demo page is not working for me it refuses to run the script because its MIME type is plain text
In the readme, you have this as the options object
{
collapse: false, // Setting to 'true' this will format the JSON into a collapsable/expandable tree
append_to: 'body', // A string of the id, class or element name to append the formatted json
list_id: 'json' // The name of the id at the root ul of the formatted JSON
}
append_to should be appendTo
It also isn't clear that when you say
JSONFormatter.format(json, {});
that json is a javascript object and not a JSON string. Initially, I did this after reading the readme.
var myObj = {"blah":"blah"};
var json = JSON.stringify(myObj);
JSONFormatter.format(json, {});
and of course that didn't work.
The other thing that might be nice is if the formatter would just return a DOM node of what you have produced.
Then I could put it wherever I want.
IE.
var node = JSONFormatter.format(json, {});
myElement.appendChild(node);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.