亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為嵌套數組元素指定一個類?

如何為嵌套數組元素指定一個類?

白衣非少年 2024-01-18 17:02:10
我有一個 JSON,存儲在一個名為PhotographersInfo的變量中,我從那里獲取數據,但我想要做的是:我想顯示與每個攝影師對應的標簽,并 為每個攝影師提供一個邊框!就像這張照片一樣結果 - 照片我使用模板文字來顯示 HTML 中的信息,目前我正在使用 join() 方法將元素轉換為字符串,但如何為每個 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 數據: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"      },
查看完整描述

1 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

使用地圖:


${item.tags.map(d => `<span class="tag">$6xb6jml</span>`).join(" ")}

其中 css 可能類似于:


.tag {

    border: 1px solid lightgray;

    border-radius: 20px; 

    padding: 5px;

}


查看完整回答
反對 回復 2024-01-18
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號