retrieve data table
The code is used to retrieve data table and generate JS object for JSON
by Andrew Qu
HTML
<table class="table table-hover table-bordered" id="testTable">
<thead>
<tr>
<th>Name</th>
<th>Map</th>
</tr>
</thead>
<tbody>
<tr>
<td>hello</td>
<td>
<select class="input-large" id="mapSelect0">
<option value=""></option>
<option value="m" selected="selected">m</option>
<option value="e">e</option>
</select>
</td>
</tr>
<tr>
<td>world</td>
<td>
<select class="input-large" id="mapSelect1">
<option value=""></option>
<option value="m">m</option>
<option value="e">e</option>
</select>
</td>
</tr>
</tbody>
</table>
JavaScript
var res = [];
var $trs = $("#testTable tbody tr");
$trs.each(function (i) {
var $tds = $(this).find('td');
var name = $tds.eq(0).text(),
map = $tds.eq(1).find('select').val();
res.push({
'name': name,
'map': map
});
});
alert(JSON.stringify(res));