在JavaScript中,我有對象的數組,表示一個任意深列表...使用jQuery生成任意深度列表
data =
[
{ title, depth },
{ title, depth },
{ title, depth },
{ title, depth },
]
...其中深度是元素有多深名單。
我想將此數據轉換爲html。
例如:
[
{ title: "one", depth : 1 },
{ title: "two", depth : 1 },
{ title: "three", depth : 2 },
{ title: "four", depth : 3 },
{ title: "five", depth : 1 },
]
成爲...
<ul>
<li><p>one</p></li>
<li>
<p>two</p>
<ul>
<li>
<p>three</p>
<ul>
<li><p>four</p></li>
</ul>
</li>
</ul>
</li>
<li><p>five</p></li>
</ul>
什麼是做到這一點的最簡單的方法,使用jQuery?
感謝
是否有必要,訂單維持?或者它可以是這樣嗎?
一個