Я пытаюсь проанализировать динамически созданную таблицу и передать результаты в программу java, чтобы записать их в базу данных. Однако функция синтаксического анализа возвращает "jsonRecords: [{" plTime ":" "}]".
. Как вы увидите из кода ниже, у меня есть таблица в таблице. Первоначально я просто пытаюсь заставить парсинг главной таблицы работать. Затем я попытаюсь проанализировать вложенную таблицу для каждой строки (содержимое перетаскивается из таблицы Activity слева и может быть пустой) и сопоставить каждую строку вложенной таблицы с главной строкой над ней (т. Е. Строка может иметь номер деятельность, связанная с этим). Если вы сможете оказать мне помощь по всей проблеме, это будет бонусом!
HTML:
<table class="table table-hover table-bordered centreTable" id="programDetailTable" style="width:100%;">
<thead>
<tr>
<th>Add</th>
<th>Time</th>
<th>Activity</th>
<th>Location</th>
<th>Equip. Needed</th>
<th>Youth to Bring</th>
<th>Leaders</th>
<th>Remove</th>
</tr>
</thead>
<!-- Populate the table with jQuery call -->
<tbody id="programDetailTablebody">
</tbody>
</table>
JS Создать таблицу
//Add an initial row if there are not currently any program lines
var newRows = "";
newRows += "<tr><td><button type='button' name='addPDRow'><span class='glyphicon glyphicon-plus'></span></button></td>";
newRows += "<td><input class='timeWidth' value='07:00'></input></td>";
//Activity table
newRows += "<td>";
newRows += "<table>";
newRows += "<tbody id='activity2Tablebody'>";
newRows += "<tr><td>";
newRows += "<input></input>";
newRows += "<div class='droppableItem'></div>";
newRows += "</td></tr>";
newRows += "</tbody>";
newRows += "</table>";
newRows +="</td>";
newRows += "<td><input class='activityWidth'></input></td>";
newRows += "<td><input></input></td>";
newRows += "<td><input></input></td>";
newRows += "<td><input></input></td>";
newRows += "<td><button type='button' name='removePDRow'><span class='glyphicon glyphicon-minus'></button></td></tr>";
$('#programDetailTablebody').append(newRows);
Таблица разбора
function getProgramLines() {
var records = [];
var keyNames = ['plTime', 'plActivity', 'plLocation', 'plEquipNeeded', 'plYouthToBring', 'plLeaders'];
$("#programDetailTable tbody tr").each(function(i) {
var record = {};
$('td', this).each(function(j) {
if (keyNames[j]){
if (j === 0 || j > 6){
//Ignore the buttons in the first and last columns
}else{
var text = $.trim($(this).text()); // GET TRIMMED TEXT
record[keyNames[j]] = text;
}
});
records.push(record);
});
return records;
}