I am making a a one page web app with JavaScript and TypeScript. I am also using the module system of JavaScript (type="module"
).
I have a class called Form
that takes in an object and creates a Form
. I have a module in which I have all the data for Registration form. There is one select in the inputs which have options field. I was those options to be assigned to the array containing names of countries. I am using an API to get the names of the countries. But I am stuck.
Below is my file RegisterFormDialog.ts
const RegisterFormData: IForm = {
//... Some other props
inputs: [
//..Some other objects.
{
name: "country",
type: "select",
label: "Country",
options: countries.map(x => x.name) // Here I want result of the api
}
]
};
export const RegisterForm = new Form(RegisterFormData);
export const RegisterFormDialog = new Dialog({
child: RegisterForm.element,
title: "Register",
dismissable: true,
onClose: () => 5,
parentElement: qs("#main") as HTMLElement
});
The other file is which have the API function. Its name is GetCountries.ts
export default async function getCountries() {
return await (await fetch("https://restcountries.eu/rest/v2/all")).json();
}
Now how could I assign the returned value of the data of API to the options property in the object.