I am facing an issue with my function, can someone help me? Here is the code:
function remove_multi_leg(): void {
if (Number($("#search_no_legs").val()) < 2) {
return;
}
const removeId: number = Number($(this).attr("data-number"));
const highestId: number = Number($("#search_no_legs").val());
if (removeId === highestId) {
$(`#multi_leg_${removeId}`).hide();
$("#search_no_legs").val(highestId);
return;
}
let i: number;
let end: number;
let asc : boolean;
for (i = removeId, end = highestId, asc = removeId <= end; asc ? i <= end : i >= end; asc ? i += 1 : i -= 1) {
$(`#search_legs_${i}_origin_text`).val($(`#search_legs_${i + 1}_origin_text`).val());
$(`#search_legs_${i}_origin_id`).val($(`#search_legs_${i + 1}_origin_id`).val());
$(`#search_legs_${i}_destination_text`).val($(`#search_legs_${i + 1}_destination_text`).val());
$(`#search_legs_${i}_destination_id`).val($(`#search_legs_${i + 1}_destination_id`).val());
}
$(`#multi_leg_${highestId - 1}`).hide();
$("#search_no_legs").val(highestId - 1);
return;
}
I encountered a strange error while running Codacy analysis on this code. Here are the details:
the "this" keyword is disallowed outside of a class body
The error seems to be in this line:
const removeId: number = Number($(this).attr("data-number"));
Can anyone suggest how I can resolve this issue?