第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

點(diǎn)擊搜索按鈕后如何渲染大量的html?

點(diǎn)擊搜索按鈕后如何渲染大量的html?

明月笑刀無(wú)情 2023-10-10 16:19:50
我正在構(gòu)建一個(gè)菜譜搜索應(yīng)用程序,但我不確定如何渲染代表我想要顯示的 30 個(gè)菜譜的大塊 html。這些食譜卡顯然必須根據(jù)我搜索的餐食類(lèi)型進(jìn)行更改。如何將 html 實(shí)現(xiàn)到我的 Js 中,以便我可以根據(jù)膳食類(lèi)型更改它?我嘗試使用 insertAdjecentHTML 來(lái)完成此操作,但因?yàn)樗粫?huì)用菜譜替換舊頁(yè)面,而是在其上替換廣告。它不起作用:不過(guò)這里是代碼:// recipe card markupconst renderRecipe = () => {  const markup = `  <div class="recipe-results__card">    <div class="recipe-results--img-container">      <img        src="${data.data.hits.recipe.image}"        alt="${data.data.hits.recipe.label}"        class="recipe-results__img"      />    </div>    <p class="recipe-results__categories">      ${limitCategories}    </p>    <h2 class="recipe-results__name">      ${data.data.hits.recipe.label}    </h2>  </div>  `;  DOM.recipeGrid.insertAdjacentHTML("beforeend", markup);};// fn to display the markup for every search resexport const renderResults = recipes => {    recipes.forEach(renderRecipe);  };
查看完整描述

1 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

  1. 連接(推送到數(shù)組)HTML,以便您有一個(gè)更新

  2. 可以使用innerHTML代替insertAdjacent來(lái)替換內(nèi)容

let html = [];

data.data.hits.forEach(recipe => {

  html.push(`

  <div class="recipe-results__card">

    <div class="recipe-results--img-container">

      <img

        src="${recipe.image}"

        alt="${recipe.label}"

        class="recipe-results__img"

      />

    </div>

    <p class="recipe-results__categories">

      ${limitCategories}

    </p>

    <h2 class="recipe-results__name">

      ${recipe.label}

    </h2>

  </div>

  `) });

document.getElementById("recipeGrid").innerHTML = html.join("");


查看完整回答
反對(duì) 回復(fù) 2023-10-10
  • 1 回答
  • 0 關(guān)注
  • 155 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)