我有一個(gè) JSON,存儲(chǔ)在一個(gè)名為PhotographersInfo的變量中,我從那里獲取數(shù)據(jù),但我想要做的是:我想顯示與每個(gè)攝影師對(duì)應(yīng)的標(biāo)簽,并 為每個(gè)攝影師提供一個(gè)邊框!就像這張照片一樣結(jié)果 - 照片我使用模板文字來(lái)顯示 HTML 中的信息,目前我正在使用 join() 方法將元素轉(zhuǎn)換為字符串,但如何為每個(gè) TAG 提供邊框?這是我的代碼:photographersInfo.forEach((item) => { const photographersDiv = document.getElementById('container'); const div = document.createElement("div"); photographersDiv.appendChild(div); div.innerHTML = ` <div class="photographerContainer"> <div class="portraitBox"> <img src="${item.portrait}" alt="photo"> </div> <h1 class="name">${item.name}</h1> <p class="city">${item.city}, ${item.country}</p> <p class="tagline">${item.tagline}</p> <p class="price">${item.price}€/jour</p> <p class="tags">${item.tags.join(" ")}</p> </div> ` });這是我的 JSON 數(shù)據(jù):let photographersInfo = [ { "name": "Mimi Keel", "id": 243, "city": "London", "country": "UK", "tags": ["#portrait", "#events", "#travel", "#animals"], "tagline": "Voir le beau dans le quotidien", "price": 400, "portrait": "/Photos/Portrait/MimiKeel.jpg" }, { "name": "Ellie-Rose Wilkens", "id": 930, "city": "Paris", "country": "France", "tags": ["#sports", "#architecture"], "tagline": "Capturer des compositions complexes", "price": 250, "portrait": "/Photos/Portrait/EllieRoseWilkens.jpg" }, { "name": "Tracy Galindo", "id": 82, "city": "Montreal", "country": "Canada", "tags": ["#art", "#fashion", "#events"], "tagline": "Photographe freelance", "price": 500, "portrait": "/Photos/Portrait/TracyGalindo.jpg" }, { "name": "Nabeel Bradford", "id": 527, "city": "Mexico City", "country": "Mexico", "tags": ["#travel", "#portrait"], "tagline": "Toujours aller de l'avant", "price": 350, "portrait": "/Photos/Portrait/NabeelBrandford.jpg" },
如何為嵌套數(shù)組元素指定一個(gè)類?
白衣非少年
2024-01-18 17:02:10