在react native中,如何只获取最后一个json值? [重复]

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

我有一个返回数组的 API 查询:

{
    "faturas": [
        {
            "vencimento_atualizado": "2020-10-05",
            "status": "Pago",
            "pagarcartao": false,
            "id": 20075
        },
        {
            "vencimento_atualizado": "2020-11-05",
            "status": "Gerado",
            "pagarcartao": false,
            "id": 20076
        },
        {
            "vencimento_atualizado": "2020-12-05",
            "status": "Gerado",
            "pagarcartao": false,
            "id": 20077
        }
    ]
}

如何根据最高的“id”只获取最后一条记录,并只过滤“已付费”和“已生成”状态?

我的代码:

return await fetch(Configs.URL+`json/data_faturas.php?cpfcnpj=${cpfcnpj}&senha=${senha}&contrato=${this.state.contrato}&ip=${Configs.IP}`)
      .then((response) => response.json())
      .then((responseJson) => {
        this.setState({
          isLoading: false,
          dataInvoice: responseJson.filter((e, index) => { return index < 2 })
        });
      }).catch((error) => {
        console.log('ERRO: '+error);
      }).done();

谢谢

reactjs json fetch native
© www.soinside.com 2019 - 2024. All rights reserved.