我有这个功能
function renderListSelecoes(data) {
// JAX-RS serializes an empty list as null, and a 'collection of one' as an object (not an 'array of one')
var list = data == null ? [] : (data.selecoes instanceof Array ? data.selecoes : [data.selecoes]);
$('#selecaoList <tr><td>').remove();
$.each(list, function(index, selecao) {
$('#selecaoList').append('<tr><td><a href="#" data-identity="' + selecao.id_selecao + '">'+selecao.nome+'</a></td></tr>');
});
}
向表中的每一行插入一些内容,如下所示:
Brasil
Argentina
Colômbia
Uruguai
Suíça
Argélia
Costa do Marfim
Gana
我怎样才能将其转换为例如 2 列,如下所示:
Brasil Costa do Marfim
Argentina Gana
Colômbia Argélia
Uruguai Suiça
这是我的 html 代码的一部分:
<div class="table-responsive container" >
<table class="table">
<tbody id="selecaoList">
</tbody>
</table>
</div>
您可以这样做:
function renderListSelecoes(data) {
// JAX-RS serializes an empty list as null, and a 'collection of one' as an object (not an 'array of one')
var list = data == null ? [] : (data.selecoes instanceof Array ? data.selecoes : [data.selecoes]);
$('#selecaoList').empty();
var tr = $( '<tr/>' ),
td = $( '<td/>' ),
row;
$.each(list, function(index, selecao) {
if( index % 2 === 0 ) {
row = tr.clone();
row.html( td.clone().html( selecao.nome ) );
} else {
row.append( td.clone().html( selecao.nome ) );
$('#selecaoList').append( row );
}
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)