I'm trying to limit the number of options that these dropdown menus will show. Is there a way to do it?
$.ajax({ url: "https://free-nba.p.rapidapi.com/teams", method: "GET", dataType: "json", headers: { 'X-RapidAPI-Key': "f8bbeecee3mshd11af53a602b7fcp133f59jsn3b4ffb3f20df", 'X-RapidAPI-Host': "free-nba.p.rapidapi.com"} }).then( (response) => { response.data.forEach ((teamObject) => { const teamName = teamObject.full_name; const teamID = teamObject.id; const htmlToAppend = ` <option value="${teamName}">${teamName}</option>` $teamDropDown.append(htmlToAppend); }); }); }
<select name="team" id="teamDropDown"> <option value = " ">Select a team</option> </select>
these dropdown menus show but cant' seem to do it.
// you can modify the number of elements here
response.data.slice(0, 10).forEach ((teamObject) => {
const teamName = teamObject.full_name;
const teamID = teamObject.id;
const htmlToAppend =
`
<option value="${teamName}">${teamName}</option>`
$teamDropDown.append(htmlToAppend);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.