JS 遍歷獲取數組中的數組的值


//文件結構

var listInfo = [ { zTit: '網站首頁', icon: './image/left.png', hicon: './image/down.png', xTit: [ { name: '關於我們', href:'./home.html', }, { name: '客戶中心', href:'./home.html', }, { name: '新聞資訊', href:'./home.html', } ], }, { zTit: '網站首頁', icon: './image/left.png', hicon: './image/down.png', xTit: [ { name: '關於我們', href:'./home.html', }, { name: '客戶中心', href:'./home.html', }, { name: '新聞資訊', href:'./home.html', } ], }, ]

//用forEach方法遍歷獲取

listInfo.forEach((item, index) => {
    selects.innerHTML +=
     `
    <li class="selects_list">
       <a></a>
        <div class="h_list_con">
            <p>${item.zTit}</p>
            <div class="icon">
                <img class="sIcon" src="${item.icon}" alt="">
                <img class="hIcon" style="display:none;" src="${item.hicon}" alt="">
            </div>
        </div>
        <div class="h_list_hid">
            ${item.xTit.map((element, index) => {
                return `<p><a href="${element.href}">${element.name}</a></p>`
            }).join('')}
           
        </div>
    </li>
    `
})


  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM