我有一個(gè)像這樣的 JSON 對象:[{"user": "poetry2", "following": ["Moderator", "shopaholic3000"]}]我正在使用這樣的 Fetch API: fetch (`/profile/${username}/following`) .then(response => response.json()) .then(profiles => { profiles.forEach(function(profile){ profileDisplay = document.createElement('button'); profileDisplay.className = "list-group-item list-group-item-action"; profileDisplay.innerHTML = ` ${profile.following}`; listFollowing.appendChild(profileDisplay); }) })現(xiàn)在,它在同一個(gè)按鈕中顯示以下用戶,如下所示:<button class="list-group-item list-group-item-action"> Moderator,shopaholic3000</button>如何修改 Fetch 調(diào)用以在單獨(dú)的按鈕中顯示以下每個(gè)用戶。更像這樣的東西:<button class="list-group-item list-group-item-action"> Moderator</button><button class="list-group-item list-group-item-action"> shopaholic3000</button>
在 Fetch 調(diào)用中迭代數(shù)組
Qyouu
2023-07-06 10:14:17