我有以下 jquery 对象:-
(function ($) {
var menu = [{
title: Main1",
href: "/"
}, {
title: "Main2",
href: "/main2",
items: [{
title: "SubMain2_1",
href: "/subMain2_1"
}, {
title: "SubMain2_2",
href: "/subMain2_2"
}]
}, {
title: "Main3",
href: "/main3",
items: [{
title: "SubMain3_1",
href: "/subMain3_1"
}, {
title: "SubMain3_2",
href: "/subMain3_2",
items: [{
title: "SubSubMain3_1",
href: "/SubSubMain3_2"
}, {
title: "SubSubMain3_2",
href: "/subSubMain3_2"
}]
}, {
title: "SubMain3_3",
href: "/subMain3_3"
}]
}, {
title: "Main4",
href: "/main4"
}];
});
我希望将其更改为
<ul>
<li class="Main"><a href="/">Main1</a></li>
<li class="Main"><a href="/main2">Main2</a></li>
<ul>
<li class="Sub"><a href="/subMain2_1">SubMain2_1</a></li>
<li class="Sub"><a href="/subMain2_2">SubMain2_2</a></li>
</ul>
<li class="Main"><a href="/main3">Main3</a></li>
<ul>
<li class="Sub"><a href="/subMain3_1">SubMain3_1</a></li>
<li class="Sub"><a href="/subMain3_2">SubMain3_2</a></li>
<ul>
<li class="SubSub"><a href="/subSubMain3_1">SubSubMain3_1</a></li>
<li class="SubSub"><a href="/subSubMain3_2">SubSubMain3_2</a></li>
</ul>
<li class="Sub"><a href="/subMain3_3">SubMain3_3</a></li>
</ul>
<li class="Main"><a href="/">Main4</a></li>
</ul>
我怎样才能做到这一点?
感谢您的帮助和时间