我有一張表。 HTML將表值轉換爲JSON值
<div class="row-fluid">
<table class="table table-striped" id="table-visual-features">
<thead>
<tr>
<th>Visual Feature</th>
<th>Type [currently not used]</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr><td>A11</td><td>Numeric [1..30]</td><td>Values to be mapped to the S1-axis</td><td><button class="action-change">edit</button> <button class="btn btn-mini btn-danger action-remove-visual-feature">remove</button></td></tr>
<tr><td>A21</td><td>Numeric [1..10 ]</td><td>Values to be mapped to the S2-axis</td><td><button class="action-change">edit</button> <button class="btn btn-mini btn-danger action-remove-visual-feature">remove</button></td></tr>
<tr><td>A31</td><td>Numeric [1..20 ]</td><td>Values to be mapped to the S3-axis</td><td><button class="action-change">edit</button> <button class="btn btn-mini btn-danger action-remove-visual-feature">remove</button></td></tr>
</tbody>
</table>
</div>
我想我的價值從錶轉換成這種形式
var features = {
features: {
"A11": {"type_feature": "Numeric [1..30]", "description_feature": "Values to be mapped to the S1-axis"},
"A21": {"type_feature": "Numeric [1..10]", "description_feature": "Values to be mapped to the S2-axis"},
"A31": {"type_feature": "Numeric [1..20]", "description_feature": "Values to be mapped to the S3-axis"}
}
};
我採取的第一個單元格的值的行中,它是「A11」。 行中第二個單元格的值是「Numeric [1..30]」。 行中第三個單元格的值是「要映射到S1軸的值」。 我們首先進入
features: {
"A11": {"type_feature": "Numeric [1..30]", "description_feature": "Values to be mapped to the S1-axis"}}
這是我的jsfiddle http://jsfiddle.net/7q3KP/
請幫我轉換價值。謝謝你在前進
不清楚你想說什麼? –
FTI:這不是JSON值。這是一個JavaScript對象。 JSON是類似於JavaScript語法的數據的*字符串表示*。如果它不是字符串,那不是JSON。 –
@Subhash:他想將HTML表格「轉換」爲JavaScript對象。 –