I encountered the following problem: I store a binary tree in the mysql table
binary-tree table
It is necessary to visualize this binary tree on WEB.
Perhaps someone has encountered a similar problem and can suggest how best to accomplish this task. In advance thanks for the answer!
After searching the libraries I came across d3. Has written an example, and like all works.
Here is my fiddle: https://jsfiddle.net/yurayazupol/vbucyuzk/1/
But then I decided to take the data from a separate json file. But after that everything stopped working. The working version is located at the link below, the interaction with the json file is in the comments in the script.js file. Can you please tell me what is wrong? https://github.com/yurayazupol/binary-tree-d3
You can't load json like this (using fs) in the browser. You can use the fetch API to load the JSON (or jQuery, axios, etc). Here's an example of using fetch:
fetch('tree.json')$
.then(response => response.json())$
.then(data => {$
root = data;$
});$
You'll need to rewrite some of your other JavaScript as the code you have written so far is synchronous and loading the json is asynchronous.
Related
I'm trying to set up a basic component that is rendered on the server and the client. The component is populated with data from a JSON API. I've got this working on the client-side by loading my data in componentDidMount and calling this.setState when it has loaded.
The problem I have is that the data isn't loaded on the server. How do I get the initial data into the server-rendered version of my component?
https://github.com/rackt/react-router/blob/latest/docs/guides/advanced/ServerRendering.md is very vague about this:
For data loading, you can use the renderProps argument to build
whatever convention you want--like adding static load methods to your
route components, or putting data loading functions on the
routes--it's up to you.
Do you have an example anywhere of how to do this? It seems like a very basic thing for a universal application to want to do!
Yup - we have https://github.com/rackt/async-props that provides a library for dealing with async data between server and client, and provides an example for doing so. If you're using a Flux framework, you'll want to make appropriate adjustments, but the basic approach will be quite similar.
I am new to wso2 API Manager, trying to set it up expose my plain HTTP POST back end calls as a REST API. I am sure this is not a new pattern that I am trying to achieve here. The requirement is to convert the JSON data coming in (has array structures) into the HTTP URL query string parameters.
After some research through the documentation and other posts on this forum, decided to go with the script mediator that would parse the JSON data and convert it to a string that can be appended to the endpoint URL. Some how I am not able to achieve this.
I have followed the following post that seems to be very straight forward. As the original poster suggested, I am also not able to use getPayloadJSON() method. Even have trouble using the work around suggested there due to JSON.parse() not working.
Link
Also, this approach of editing the service bus configuration from source view does not sound like the correct option. Is there another elegant solution to achieve this? Thanks for the help in advance.
I was able to get both methods working by using an external script instead of the inline java script. Thanks
I am a Drupal 7 newbie and I am hoping someone can help me.
I have a REST API on another server and there is method there which return JSON data, the data is the same for all Drupal users.
My question is that how could I display this data in Drupal? I need a page and on that I would like this JSON rendered as a HTML table.
Any feedback would be most appreciated.
There is no module AFAIK that will just automatically pull data from any arbitrary API and theme it nicely. You are going to need to make a custom module.
To do what you are saying could probably be done in as few as 15 lines of code, but you will need to learn how to create a module first.
Check out: https://www.drupal.org/node/1074360
Once you have created your module, you will need a hook_menu() function to create the page to display the json results.
In the callback function for that page you will need to call your API and then you can theme the results into a table by using theme('table', array('rows' => $rows, 'header' => $header));
There is a decent tutorial here:
http://alvinalexander.com/drupal/drupal-7-form-theme-table-module-example
Assuming you have some experience programming with PHP then expect to spend 3-4 hours on this (based on learning curve and reading involved).
First of all I'm very confused with this "JSON" thing, I can't completely get all the concepts but what I actually want to do is some kind of recipes Mobile Phonegap/kendo-UI(or whatever framework) App which should load data from JSON object. But I don't have a website where I could store data. So, what would be options to save and load data from JSON to my app? I mean it's very confusing to ask this, because I actually can't get the JSON, so I'am ready to get a lot of Dislikes but I want to know how to do a thing like that. I don;t know what URL to write and other stuff.
Hope someone will get what I acutally want and if this idea for loading data from JSON is not what I need, hope someone would like to offer other possibilities. Thank you.
Yes, you can technically save JSON files locally to your app, then retrieve that data locally. At the end of the day, it's not much different than getting it from a web service (other than the fact that it's going to be static data).
Not to get into too much detail here (This site has plenty of info), but JSON is a lightweight flavor of XML for passing data back and forth, very suitable for web services. All it is is key-value pairs. So, in your case, it'll be something like:
{ ["RecipeID" : 1,
"RecipeName" : "PB&J",
"RecipeIngredients" : ["Peanut butter", "Jelly", "Bread" ],
"RecipeDirections" : "If you really have to look this up on an app..."],
["RecipeID" : 2,
// ...
]
}
As you can see, it reads pretty clean and is easy to parse. So, in PhoneGap, you'd probably use jQuery and do something like,
$.getJSON("URLorLocationOfJSONfile", null, function(recipes) {
$.each(recipes, function(i,r) {
alert("Today, I'd like to eat... " + r.RecipeName);
)};
)};
And thus iterate through the JSON contents. Put them in a list or something. Whatever you'd like at that point. I build all my PhoneGap apps with JSON on the backend, so you're going in the right direction with that.
You can host the JSON file somewhere out there if you don't want to build an API for it, too. Just replace it when you get new recipes.
Hope that's a start.
I've been using Google Tools (library, templating) for almost a year... and I came to the point where a I have to connect the backend with all the templates i've been working on. The backend receives the data in JSON format.
Here's my problem. I want to submit a JSON that represents my object model in the backend and I know closure library offers this...
var json = goog.json.serialize(goog.dom.forms.getFormDataMap(form).toObject());
Problem is that the method getFormDataMap returns a goog.structs.Map which works like a hashMap... It means that all values of the form submitted are nested into arrays.
I was wondering if anyone has found a solution to this. I know that there is some library that does the trick like this one (https://github.com/maxatwork/form2js) but I can't believe that closure doesn't have anything to deal with this problem.
Thanks a lot !
why not access the data yourself and build the data structure you require, it is not like this will be a bottleneck of any sorts.