我有以下 html 表,其中包含行和列,每个行和列都包含一个带有文本的 td、一个选择和一个输入 [type='text']。每行还有一个最后一个 td 用于从表中删除行,与将表行保存为 json 无关,可以忽略。
<table id="columnsTable" class="table white-table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Column</th>
<th>Condition</th>
<th>Value</th>
<th></th>
</tr>
</thead>
<tbody id="columnsTableBody">
<tr id="StudentInfo.FirstName" class="StudentInfo.FirstName" name="StudentInfo.FirstName">
<td>FirstName</td>
<td>
<select id="StudentInfo.FirstName-condition">
<option value="LIKE">CONTAINS</option>
<option value="=">EQUALS</option>
<option value="!=">NOT EQUAL</option>
<option value=">">GREATER THAN</option>
<option value="<">LESS THAN</option>
<option value=">=">GREATER THAN OR EQUAL TO</option>
<option value="<=">LESS THAN OR EQUAL TO</option>
</select></td>
<td>
<input type="text" id="StudentInfo.FirstName-value" class="required" title="Value is required"></td>
<td>
<label>
<input type="checkbox" id="StudentInfo.FirstName-checkbox"></label></td>
</tr>
<tr id="StudentInfo.LastName" class="StudentInfo.LastName" name="StudentInfo.LastName">
<td>LastName</td>
<td>
<select id="StudentInfo.LastName-condition">
<option value="LIKE">CONTAINS</option>
<option value="=">EQUALS</option>
<option value="!=">NOT EQUAL</option>
<option value=">">GREATER THAN</option>
<option value="<">LESS THAN</option>
<option value=">=">GREATER THAN OR EQUAL TO</option>
<option value="<=">LESS THAN OR EQUAL TO</option>
</select></td>
<td>
<input type="text" id="StudentInfo.LastName-value" class="required" title="Value is required"></td>
<td>
<label>
<input type="checkbox" id="StudentInfo.LastName-checkbox"></label></td>
</tr>
<tr id="StudentInfo.CurrentCollege" class="StudentInfo.CurrentCollege" name="StudentInfo.CurrentCollege">
<td>CurrentCollege</td>
<td>
<select id="StudentInfo.CurrentCollege-condition">
<option value="LIKE">CONTAINS</option>
<option value="=">EQUALS</option>
<option value="!=">NOT EQUAL</option>
<option value=">">GREATER THAN</option>
<option value="<">LESS THAN</option>
<option value=">=">GREATER THAN OR EQUAL TO</option>
<option value="<=">LESS THAN OR EQUAL TO</option>
</select></td>
<td>
<input type="text" id="StudentInfo.CurrentCollege-value" class="required" title="Value is required"></td>
<td>
<label>
<input type="checkbox" id="StudentInfo.CurrentCollege-checkbox"></label></td>
</tr>
<tr id="StudentInfo.EmailAddress" class="StudentInfo.EmailAddress" name="StudentInfo.EmailAddress">
<td>EmailAddress</td>
<td>
<select id="StudentInfo.EmailAddress-condition">
<option value="LIKE">CONTAINS</option>
<option value="=">EQUALS</option>
<option value="!=">NOT EQUAL</option>
<option value=">">GREATER THAN</option>
<option value="<">LESS THAN</option>
<option value=">=">GREATER THAN OR EQUAL TO</option>
<option value="<=">LESS THAN OR EQUAL TO</option>
</select></td>
<td>
<input type="text" id="StudentInfo.EmailAddress-value" class="required" title="Value is required"></td>
<td>
<label>
<input type="checkbox" id="StudentInfo.EmailAddress-checkbox"></label></td>
</tr>
<tr id="StudentInfo.Status" class="StudentInfo.Status" name="StudentInfo.Status">
<td>Status</td>
<td>
<select id="StudentInfo.Status-condition">
<option value="LIKE">CONTAINS</option>
<option value="=">EQUALS</option>
<option value="!=">NOT EQUAL</option>
<option value=">">GREATER THAN</option>
<option value="<">LESS THAN</option>
<option value=">=">GREATER THAN OR EQUAL TO</option>
<option value="<=">LESS THAN OR EQUAL TO</option>
</select></td>
<td>
<input type="text" id="StudentInfo.Status-value" class="required" title="Value is required"></td>
<td>
<label>
<input type="checkbox" id="StudentInfo.Status-checkbox"></label></td>
</tr>
</tbody>
</table>
如何将行保存为以下格式的 JSON?,以便我可以循环返回它以从 JSON 重新构建表行。
columns: {
StudentInfo.FirstName: {
condition: 'CONTAINS',
value: 'Carl'
}
StudentInfo.LastName: {
condition: 'EQUALS',
value: 'W'
}
}