Javascript搜索输入

问题描述 投票:0回答:2

我有以下代码。

 data.forEach((element) => {
//nuova feat di ES6 , passando i dati in questo modo le mie const assumono il valore di element.confirmed , etc
console.log(element);
var {
  confirmed,
  countryregion,
  location,
  provincestate,
  deaths,
  recovered,
} = element;
// console.log(countryregion);
window.onkeyup = keyup;

//creates a global Javascript variable
var inputTextValue;

function keyup(e) {
  //setting your input text to the global Javascript Variable for every key press
  inputTextValue = e.target.value;

  //listens for you to press the ENTER key, at which point your web address will change to the one you have input in the search box
  if (e.keyCode == 13) {
    if (inputTextValue == countryregion || inputTextValue == provincestate) {
      return console.log("THIS OBJECT");
    } else {
      return console.log("THIS OBJECT DON'T EXIST");
    }
  }
}

我想输入搜索内容。在实践中,我想确保当用户插入搜索输入中的元素等于Provincestate或countryregion时,它返回与该对象有关的所有数据。例如,如果我在输入中写摩洛哥,我将在此返回具有死亡,恢复和确认值的对象。如enter image description here数组数据是来自api的对象数组。但是我有各种各样的问题实际上,仅将省份或国家/地区的最后一个元素进行比较。您能帮我吗?

javascript search
2个回答
0
投票

如下更改您的if条件,希望这会有所帮助


0
投票

© www.soinside.com 2019 - 2024. All rights reserved.