I can not figure out.
<table id="table"></table> <script> var r = new RegExp("\x27+","g"); var str = "[[' ',' ',' '],[' ',' ',' '],[' ',' ',' ']]"; // переменная находится во внешнем файле var min_map = str.replace(r, "\x22"); // тут я меняю кавычки на двойные, потому что с сервера должен придти ответ с одинарными. var table = document.querySelector('#table'); var arr = JSON.parse(min_map); fillTable(table, arr); function fillTable(table, arr) { for (var i = 0; i < arr.length; i++) { var tr = document.createElement('tr'); for (var j = 0; j < arr[i].length; j++) { var td = document.createElement('td'); td.innerHTML = arr[i][j]; tr.appendChild(td); } table.appendChild(tr); } } In general in the piece above, the table is generated from the JSON string.
The variable str changes its value, new, derived from the websocket. With this kind of way. But my table renders only the first state of the variable. How can I catch changes in a variable and redraw the table?
It looks like I didn’t ask the right question at all) I’m checking the external file. it's a little different. when a variable changes, a new value is added (!) on the page (in the table). that is, my spreadsheet grows with every new query. I need the contents of the 'id table' to change to a new table
even clearer: this is the case -
table [1][2][3] [4][5][6] [7][8][9] __ запрос [s][o][h] [k][h][g] [d][t][y] how it should look like:
table [1][2][3] [4][5][6] [7][8][9] ___запрос table [s][o][h] [k][h][g] [d][t][y] That is, each query, the matrix must be updated without reloading the page, without increasing the cells in the table.
Threat damn why the text is bold?