简体   繁体   English

从 API 中获取所有需要满足提取条件的项目或数据

[英]Get all items or data from API where they need to meet a condition to be fetched

I want to display a list of all items or data from an API source where the VirtualOrganization (or some other data) is the one i specify (like ATCclub).我想显示来自 API 源的所有项目或数据的列表,其中 VirtualOrganization(或其他一些数据)是我指定的(如 ATCclub)。 I use Axios to get the data.我使用 Axios 来获取数据。

Baicicly I only want to only fetch the JSON data from the API where the VirtualOrganization is the right one, and then display it. Baicicly,我只想从 VirtualOrganization 正确的 API 中获取 JSON 数据,然后显示它。

Here is my code:这是我的代码:

let data;
axios.get(URLBASE + '/flights/' + expert + '?apikey=' + APIKEY, {
    params: {
        virtualOrganization: "ATCclub"
    }
  })
.then(response => {
    console.log(response.data.result);
     if (response.data.result.virtualOrganization === "ATCclub") {
        for (let i = 0; i < response.data.result.virtualOrganization.array.length; i++) {
            document.getElementById("username").innerHTML = response.data.result.username;
            document.getElementById("aircraftId").innerHTML = response.data.result.aircraftId;
            document.getElementById("heading").innerHTML = response.data.result.heading;
            document.getElementById("latitude").innerHTML = response.data.result.latitude;
            document.getElementById("longitude").innerHTML = response.data.result.longitude;
            document.getElementById("speed").innerHTML = response.data.result.speed;
            document.getElementById("altitude").innerHTML = response.data.result.altitude;
        }
    }
    
    
})
.catch(error => console.error(error));

NOTE: I have managed to display one row from the JSON.注意:我已经设法从 JSON 中显示了一行。

I found a solution after someone sent me a answer to "filter it after".在有人向我发送“过滤后”的答案后,我找到了解决方案。 Then I came up with this:然后我想出了这个:

// resF (result of flights)
const resF = response.data.result.filter(function (e){
        return e.virtualOrganization === "ATCclub";
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM