How to display the contents of a two-dimensional array of JSON Object in an HTML table

I am trying to display the contents of a Javascript object in an HMTL / CSS table. Groovy's two-dimensional array looks like this (it's just a fragment, not a complete one):

[[null, Pyjamas , Oreillers Traversins, Linge de lit, Protection literie, Surmatelas, Linge de lit , Couettes, Linge de bain], [Pyjamas , null, .3333333333333333, 0.16666666666666666, 0.16, 0.16, null, null, null]]

One array corresponds to one row in my table. A Javascript object is created from a Groovy controller such as

[matrix: matrix as JSON]

And so as I think, I need to get the full table in GSP / Javascript and display it (in my console, not in my table).

<script>
  var matrix = ${matrix};
  var matrixTab = JSON.stringify(matrix);
  console.log(matrixTab);
</script>

What the HMTL table looks like doesn't matter much. One more thing, I use firebug, and when I try to catch my array, the console shows me this error . Any ideas?

+4
1

JSON.stringify() , JavaScript. ${matrix} , , :

var matrix = '[[null, Pyjamas , Oreillers Traversins, Linge de lit, Protection literie, Surmatelas, Linge de lit , Couettes, Linge de bain], [Pyjamas , null, .3333333333333333, 0.16666666666666666, 0.16, 0.16, null, null, null]]'
// OR
var matrix = ${matrix}
var matrixTab = JSON.parse(matrix);

matrixTab .

+2

Source: https://habr.com/ru/post/1663838/


All Articles