Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

javascript - 如何在Vanilla JS中循环菜单和子菜单(How looping Menu & Submenus in Vanilla js)

How looping Menu & Submenus in Vanilla js?

(如何在Vanilla JS中循环菜单和子菜单?)

What would be the correct procedure to loop thru a nested menu?

(什么是通过嵌套菜单循环的正确程序?)

Thanks in advance.

(提前致谢。)

JSON:

(JSON:)

[
   {
      "name":"Home",
      "link":"/",
      "subMenus":[
         {
            "name":"Sub Menu 1-2"
         },
         {
            "name":"Sub Menu 1-2"
         },
         {
            "name":"Sub Menu 1-3"
         }
      ]
   },
   {
      "name":"About",
      "link":"/#/about"
   },
   {
      "name":"Pages"
   },
   {
      "name":"News",
      "subMenus":[
         {
            "name":"Sub Menu 4-2"
         },
         {
            "name":"Sub Menu 4-2"
         },
         {
            "name":"Sub Menu 4-3"
         }
      ]
   },
   {
      "name":"Contacts"
   }
]

HTML:

(HTML:)

<nav class="header-nav">
  <ul class="main-menu">
    <li>
      <a href="#" class="active">
        Home
      </a>
    </li>
    <li>
      <a href="#">About Us</a>
    </li>
    <li>
      <a href="#">Pages</a>
      <ul class="sub-menu">
        <li>
          <a href="#">About Us</a>
        </li>
        <li>
          <a href="#">Loans</a>
        </li>
        <li>
          <a href="#">elements</a>
        </li>
      </ul>
    </li>
    <li>
      <a href="#">News</a>
    </li>
    <li>
      <a href="#">Contact</a>
    </li>
  </ul>
</nav>
  ask by LukDev translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...