Ошибка загадки JavaScript - слушатель событий не уволенJavascript

Форум по Javascript
Ответить
Anonymous
 Ошибка загадки JavaScript - слушатель событий не уволен

Сообщение Anonymous »

javascript Боги! < /p>
У меня есть код JS здесь, который не работает. Может ли кто -нибудь указать, что я делаю здесь не так? Но слушатели событий, ответственные за обнаружение изменений в поле ввода, не работает.if (document.querySelector(".rooms-page")) {
// Room country filter
new RoomRegionFiter(
"id_country_input",
"country_datalist",
"region_datalist",
csrftoken);
}
< /code>
class RoomRegionFiter {
constructor (id_country_input, country_datalist, region_datalist, csrftoken) {
this.input = document.getElementById(id_country_input);
this.country_dataList = document.getElementById(country_datalist);
this.region_datalist = document.getElementById(region_datalist);
this.csrftoken = csrftoken;

this.initializeCountryEventListeners();
}

initializeCountryEventListeners() {
this.loadCountryList()

this.input.addEventListener("change", () => {
console.info("Listening for changes")
const selected_country = this.input.value;
this.loadRegionList(selected_country);
});

this.input.addEventListener("input", () => {
console.info("Listening for input")
const selected_country = this.input.value;
this.loadRegionList(selected_country);

});
};

// Loads all the countries on page load
async loadCountryList() {
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const port = window.location.port;
const endPoint = `${protocol}//${hostname}:${port}/roomfiltercountry/`;

try {
const response = await fetch(endPoint, {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRFToken": this.csrftoken
}
});

if (!response.ok) {
console.log("Response is not available");
}

const json_response = await response.json();
const countries = json_response.countries

let dataListOptions = ``;

for (const country of countries) {
dataListOptions += ``
}

this.country_dataList.innerHTML = dataListOptions

} catch (error) {
console.log(error.message);
}
}

// Whenever a country is selected, loads the regions
async loadRegionList() {
console.log("Building URL")
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const port = window.location.port;
const endPoint = `${protocol}//${hostname}:${port}/roomfilterregion/`;
const url = `${endPoint}?country=${encodeURIComponent(selected_country)}`;
console.log(url)

try {
const response = await fetch(url, {
method: "GET",
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRFToken": this.csrftoken
},
});

if (!response.ok) {
console.log("Response is not available");
}

const json_response = await response.json();
const regions = json_response.regions

console.log(json_response)
console.log(regions)

let dataListOptions = ``;

for (const region of regions) {
dataListOptions += ``
}

this.region_datalist.innerHTML = dataListOptions

} catch (error) {
console.log(error.message);
}
}

};
< /code>
Someone, please?

Подробнее здесь: https://stackoverflow.com/questions/795 ... s-not-fire
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»