1

I have this structure:

HTML part:

<table id="table_div" class="table table-striped table-condensed"><tbody></tbody></table>

JS part:

var data = json_response['data'];

  $("#table_div").html('<thead><tr><td>TIMESTAMP</td><td>VALUE</td></tr></thead>');

  $.each(data, function(index, value) {
    $('#table_div > tbody:last').append('<tr><td>' + value + '<td></tr>'); 
  });   

Now, my vector data, taken from the java console, is this for example:

{"data": [[1348754599, 0.0], [1348754639, 0.0], [1348754680, 0.0], [1348754721, 0.0], [1348754761, 0.0], [1348754802, 0.0], [1348754842, 0.0], [1348754883, 0.0], [1348754924, 0.0], [1348754964, 0.0], [1348755005, 0.0], [1348755045, 0.0], [1348755086, 0.0], [1348755126, 0.0], [1348755167, 0.0], [1348755208, 0.0]]}

And at this moment the result is that the timestamp and the value are toghether under TIMESTAMP, but column VALUE is empty.

TIMESTAMP   VALUE

1348756790,0
1348756830,0
1348756871,0
1348756911,0
1348756952,0
1348756992,0
1348757033,0

How I can i do to have

Timestamp Value
12876      0
129487     1

Thank you very much!

*EDIT*

This is the html generated now:

<table id="table_div" class="table table-striped table-condensed"><tbody><tr><td>TIMESTAMP</td><td>VALUE</td></tr><tr><td>1348760408,0</td><td></td></tr><tr><td>1348760448,0</td><td></td></tr></tbody></table>

1 Answer 1

2

My previous answer was bogus. I misremembered how $.each() works.

Your original code is correct except that you're not breaking each element part into its timestamp and value components. I think this code will do what you want:

  $("#table_div").html('<thead><tr><td>TIMESTAMP</td><td>VALUE</td></tr></thead>');

  $.each(data, function(index, value) {
    $('#table_div > tbody:last').append('<tr><td>' + value[0] + '</td><td>' + value[1] +'</td></tr>'); 
  });  
Sign up to request clarification or add additional context in comments.

2 Comments

It don't works, but I'm not sure on the structure of my json vector. In the response to the request of the page, from the developer console, I have this vector {"data": [[1348757520, 0.0], [1348757560, 0.0], [1348757601, 0.0], [1348757641, 0.0]]} but if I print the data variable in the html page I have this: 1348757520,0,1348757560,0,1348757601,0,1348757641,0
You'll need to update the question with the actual HTML that is being generated from the code I gave you so we can further analyze it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.