Hi
I’m trying to display my api in the wix code dropdown.
in the terminal, the backend is returning an array in table form with the values of the api.
In the PAGE CODE is not showing in the dropdown button a forEach error appears. “Cannot read property ‘forEach’ of undefined”
import { lerLista } from 'backend/manualAPI_vs2';
// /*FRONTEND */
$w.onReady(() => {
listarEquipamentos()
})
function listarEquipamentos() {
let opcoes = []
let listaDeEquipamentos = []
lerLista("equipamentos")
.then(async (lista) => {
console. log(lista)
await lista. Equipamentos.forEach((value, i) => {
listaDeEquipamentos. push(value. nome_equipamento + "***" + value. id)
})
listaDeEquipamentos. sort(function (a, b) {
return a. localeCompare(b);
});
await listaDeEquipamentos. forEach((pais, index) => {
let dados = pais. split("***")
opcoes. push({ "value": String(dados[1]), "label": dados[0] })
})
$w("#dropdown1"). options = opcoes
$w("#dropdown1"). enable()
})
}
backend
/*BACKEND */
import { fetch } from 'wix-fetch';
let ret
export async function lerLista(equipamentos) {
const headers = {
"Content-Type": "application/x-www-form-urlencoded"
};
const request = {
"method": "get",
"headers": headers,
};
const url = 'http://3b88a1d8ac67. ngrok. io/equipamentos';
console.log("Url: " + url + '/?format=json');
let fullUrl = url + '/?format=json';
try {
let httpResponse = await fetch(fullUrl, request)
if (httpResponse. ok) {
ret = await httpResponse. json()
}
} catch (erro) {
ret = await erro
}
return ret
}
display