У меня есть таблица рядом, когда я ввожу данные в таблицу и сохраняю, она возвращает данные первой таблицы как
[{"circuit_no_left":"1","rating_left":"3","description_left":"test1","circuit_no_right":"2","rating_right":"5","description_right":"test2"},{"circuit_no_left":"3","rating_left":"","description_left":"","circuit_no_right":"4","rating_right":"","description_right":""},{"circuit_no_left":"5","rating_left":"","description_left":"","circuit_no_right":"6","rating_right":"","description_right":""},{"circuit_no_left":"7","rating_left":"","description_left":"","circuit_no_right":"8","rating_right":"","description_right":""}]
Я хочу вывод, как этот
[{"circuit_no_left":"1","rating_left":"3","description_left":"test1"},{"circuit_no_right":"2","rating_right":"5","description_right":"test2"},{"circuit_no_left":"3","rating_left":"","description_left":""},{"circuit_no_right":"4","rating_right":"","description_right":""},{"circuit_no_left":"5","rating_left":"","description_left":""},{"circuit_no_right":"6","rating_right":"","description_right":""},{"circuit_no_left":"7","rating_left":"","description_left":""},{"circuit_no_right":"8","rating_right":"","description_right":""}]
Я просто хочу одна строка таблицы в одном объекте. Я получаю соседний стол в одном объекте, который не является правильным. Столбец слева в одном объекте и столбец справа в другом объекте.
html:
<div class="table-responsive">
<table id="table" class="table table-bordered custom_table">
<thead>
<tr>
<th style="width: 72px;">Circuit</th>
<th style="width: 72px;">Rating</th>
<th>Description</th>
<th style="width: 72px;">Circuit</th>
<th style="width: 72px;">Rating</th>
<th>Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
Сценарий:
var table = document.getElementById('table');
var jsonArr = [];
for (var i = 1, row; row = table.rows[i]; i++) {
var col = row.cells;
var jsonObj = {
circuit_no_left: col[0].innerHTML,
rating_left: col[1].innerHTML,
description_left: col[2].innerHTML,
circuit_no_right: col[3].innerHTML,
rating_right: col[4].innerHTML,
description_right: col[5].innerHTML,
}
jsonArr.push(jsonObj);
}
this.table_data = JSON.stringify(jsonArr);
console.log('tableData', this.table_data);