当我使用for循环时,在
for (var h = 0; h < xt.length; h++) {
var heart = '';
console.log(xt[h]);
if (row[0] == xt[h]) {
heart = 'icon-heart';
} else {
heart = 'icon- heart1';
}
}
但是当我使用return指令时,循环停止了:
for (var h = 0; h < xt.length; h++) {
var heart = '';
console.log(xt[h]);
if (row[0] == xt[h]) {
heart = 'icon-heart';
} else {
heart = 'icon-heart1';
}
return '<i class="' + heart + '" onClick="addFAv(this)" data-id="' + row[0] + '" data-name="' + row[1] + '"></i> <a href="#" class="icon-line-clipboard i-circled i-small"></a> <a href="#" class="icon-file-alt2 i-circled i-small"></a>';
}
你知道为什么吗?
函数中的整个代码是
$('#recevabilite').dataTable({
"scrollY": "200px",
"scrollCollapse": true,
"paging": false,
stateSave: true,
"dom": '<"#recev.top">irt',
"columnDefs": [{
"visible": false,
"targets": [3]
},
{
"render": function(data, type, row) {
// var date1 = new Date()+10J;
//affichage des icones
var x = localStorage.getItem("listeFavoris");
xt = x.split(',');
for (var h = 0; h < xt.length; h++) {
var heart = '';
console.log(xt[h]);
if (row[0] == xt[h]) {
heart = 'icon-heart';
} else {
heart = 'icon-heart1';
}
return '<i class="' + heart + '" onClick="addFAv(this)" data-id="' + row[0] + '" data-name="' + row[1] + '"></i> <a href="#" class="icon-line-clipboard i-circled i-small"></a> <a href="#" class="icon-file-alt2 i-circled i-small"></a>';
}
谢谢
https://stackoverflow.com/questions/56568936
复制相似问题