Any idea why this code doesnt work? Until the commented part everything works. I get all the data from the api but cant filter it.
fetch(url)
.then((res) => res.json())
.then((data) => {
opt = data;
console.log(data);
opt.forEach((item) => {
options.push({
//v: `SUBSCRIBE ${item.deviceName} ${item.name} WebEvent/1.0`,
v: `SUBSCRIBE ${item.name} WebEvent/1.0`,
t: item.name,
});
});
for (let i = 0; i < options.length; i++) {
let value = options[i].v;
let text = options[i].t;
$("#node-input-options").append(
$("<option></option>").attr("value", value).text(text)
);
// Until Here Everything Works
let inputEl = $("#node-input-filter");
inputEl.on("keyup", () => {
var keyword = $("#node-input-filter");
var fleet = $("#node-input-options");
var txt = fleet.options[i].text();
if (
txt.substring(0, keyword.length).toLowerCase() !==
keyword.toLowerCase() &&
keyword.trim() !== ""
) {
fleet.options[i].style.display = "none";
} else {
fleet.options[i].style.display = "list-item";
}