I have a test api where I would like it to be displayed in the dropdown.
The backend code is returning a null value. Page code I tried to follow an example of a user here on the forum and was unsuccessful. can anybody help me ?
PAGE CODE
import { manualApi_vs1 } from 'backend/manualAPI_vs2';
import { session } from 'wix-storage';
import wixData from 'wix-data';
let equipamentos = session. getItem("equipamentos");
$w.onReady(function () {
manualApi_vs1(equipamentos)
. then((Equipamentos) => {
console. log(Equipamentos);
const uniqueTitles = getUniqueTitles(Equipamentos. id);
$w("#dropdown1"). options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items. map(item => item. line_1);
return [ ... new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList. map(curr => {
return { label: curr, value: curr };
});
}
})
BACKEND CODE
import { fetch } from 'wix-fetch';
export function manualApi_vs1(equipamentos) {
// const url = 'http:// 3b88a1d8ac67. ngrok. io/equipamentos/?format=json';
// console. log("Url: " + url);
const url = 'http://3b88a1d8ac67. ngrok. io/equipamentos/';
console. log("Url: " + url + equipamentos + '/?format=json');
let fullUrl = url + equipamentos + '/?format=json';
return fetch(fullUrl, { "method": "get" })
. then((httpResponse) => {
if (httpResponse. ok) {
let Equipamentos = httpResponse. json();
return Equipamentos;
}
})
}