我正在使用 Json2HTML jquery 插件json2html从 JSON 数据构建一个表,这是当前状态:http: //jsfiddle.net/hamiltonlima/7u8v9wdq/ 我想要的是在处理过程中比较 currentID,因此可以添加“.active”上课,有什么建议吗?
html
<div class="container">
<p>
<table id="placar" class="table table-condensed table-bordered">
<thead>
<tr>
<th>#</th>
<th>Luchador</th>
<th>K</th>
<th>D</th>
<th>Pontos</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
Javascript
var data = [{
'order': '1',
'name': 'nheco',
'k': '3',
'd': '0',
'score': '121',
'id': '540'
}, {
'order': '2',
'name': 'boingo',
'k': '15',
'd': '3',
'score': '122',
'id': '541'
}, {
'order': '3',
'name': 'Oswaldo',
'k': '0',
'd': '23',
'score': '123',
'id': '542'
}];
var currentID = 541;
var transform = {
tag: 'tr',
children: [{
"tag": "td",
"html": "${order}"
}, {
"tag": "td",
"html": "${name}"
}, {
"tag": "td",
"html": "${k}"
}, {
"tag": "td",
"html": "${d}"
}, {
"tag": "td",
"html": "${score}"
}]
};
$('#placar > tbody ').json2html(data, transform);