B
B
Blacksmith_JS2017-03-14 12:06:40
JavaScript
Blacksmith_JS, 2017-03-14 12:06:40

Reading and translating json data into ES6 table?

The essence of the question is how can I read the data from the JSON file, which are there in the form of an array, in order to transfer them to the finished table?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2017-03-14
@Blacksmith_JS

I’ll add to the previous question, because I see the tag 'react'
1) you need to realize that since new data comes in, then we have some kind of "changeable piece", therefore, it will be necessary to use state, therefore, you need to set this.state in constructor, with some initial data, for example "an empty array"
2) you need to execute a request after the component is on the page, the life cycle method - componentDidMount
is suitable for this 3) at the time of componentDidMount you can execute a request using any library, for example, jquery from the answer above, but more often they use npm-fetch, axios and the like with react .. or you can get by with the standard XHR object ...
4) after executing the request, for a successful response, you must change the state, that is, call this.setState
5) after completing the steps above, the react will call the render method - in which you will already draw the table, based on your data from the state

X
xutesayor, 2017-03-14
@xutesayor

$.getJSON( "ajax/test.json", function( data ) {
  
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question