I tried to jump out of the outer loop when a certain condition is met. So I labeled each loop and use break statement to specify which loop I want to break but it didn't work. Below are my codes, the console.log statement inside the else block still print 1 to the console even though break statement executed. What did I do wrong in the javascript codes?
HTML for table:
<table class="t-Report-report ui-sortable" id="seq_report">
<thead>
<tr class="ui-sortable-handle">
<th class="t-Report-colHead" align="left" id="PK_DISPLAY"> </th>
<th class="t-Report-colHead" align="center" id="POS_NBR">Position</th>
<th class="t-Report-colHead" align="center" id="DISP_VAL">Description</th>
<th class="t-Report-colHead" align="center" id="SEQ_NBR">Seq</th>
<th class="t-Report-colHead" align="center" id="PERM"></th>
</tr>
</thead>
<tbody>
<tr data-id="19691" class="ui-sortable-handle">
<td class="t-Report-cell" headers="PK_DISPLAY"><a href="#" data-id="19691"></a></td>
<td class="t-Report-cell" headers="POS_NBR">05M</td>
<td class="t-Report-cell" headers="DISP_VAL">t05</td>
<td class="t-Report-cell" headers="SEQ_NBR">1</td>
<td class="t-Report-cell" headers="PERM">Perm</td>
</tr>
<tr data-id="19692" class="ui-sortable-handle">
<td class="t-Report-cell" headers="PK_DISPLAY"><a href="#" data-id="19692"></a></td>
<td class="t-Report-cell" headers="POS_NBR">06M</td>
<td class="t-Report-cell" headers="DISP_VAL">t06</td>
<td class="t-Report-cell" headers="SEQ_NBR">2</td>
<td class="t-Report-cell" headers="PERM">Perm</td>
</tr>
<tr data-id="19690" class="ui-sortable-handle">
<td class="t-Report-cell" headers="PK_DISPLAY"><a href="#" data-id="19690"></a></td>
<td class="t-Report-cell" headers="POS_NBR">04M</td>
<td class="t-Report-cell" headers="DISP_VAL">t04</td>
<td class="t-Report-cell" headers="SEQ_NBR">3</td>
<td class="t-Report-cell" headers="PERM">Perm</td>
</tr>
<tr data-id="19687" class="ui-sortable-handle">
<td class="t-Report-cell" headers="PK_DISPLAY"><a href="#" data-id="19687"></a></td>
<td class="t-Report-cell" headers="POS_NBR">04M</td>
<td class="t-Report-cell" headers="DISP_VAL">t04</td>
<td class="t-Report-cell" headers="SEQ_NBR">4</td>
<td class="t-Report-cell" headers="PERM">Temp</td>
</tr>
</tbody>
</table>
Javascript:
function makeSortable(pRegionID) {
var $r = $("#report_" + pRegionID);
var r = $r[0];// add ID to TR element so we know the correct position
var $perm;
var $obj;
$r.find("[headers='PK_DISPLAY'] a").each(function () {
//console.log($(this));
$(this).parent().parent().attr('data-id', $(this).data("id"));
// $(this).closest('tr').attr('data-id',$(this).data("id"));
});// finally make it sortable
$r.find("table.t-Report-report").sortable({
items: 'tr'
, containment: r
, helper: fixHelper
, update: function (event, ui) {
var found = 0;
$obj = $r.find("[headers='POS_NBR']");
$perm = $obj.next().next().next();
loop1:for (var i = 0; i < $obj.length - 1; i++) {
loop2:for (var j = 0; j < $obj.length - 1 - i; j++) {
if ($obj[i].innerHTML == $obj[i + 1 + j].innerHTML && $perm[i].innerHTML == 'Temp') {
apex.message.alert("Go out");
apex.event.trigger($r, 'apexrefresh');
break loop1;
}else{
console.log(1);
updateDisplaySeq(r);
}
}
}
}
});
}