Answer the question
In order to leave comments, you need to log in
How to create a recursion in pug with creating a list from an object?
Given an object
{
"label": "蟆",
"children": [
{
"label": "虫"
},
{
"label": "莫",
"children": [
{
"label": "艹"
},
{
"label": "旲",
"children": [
{
"label": "日"
},
{
"label": "大"
}
]
}
]
}
]
}
<ul>
<li>蟆
<ul>
<li>虫</li>
<li>莫
<ul>
<li>艹</li>
<li>旲
<ul>
<li>日</li>
<li>大</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Answer the question
In order to leave comments, you need to log in
For example, like this, as an option
-
var obj = {
"label": "蟆",
"children": [
{
"label": "虫"
},
{
"label": "莫",
"children": [
{
"label": "艹"
},
{
"label": "旲",
"children": [
{
"label": "日"
},
{
"label": "大"
}
]
}
]
}
]
}
mixin unpackKanji(obj)
if(Array.isArray(obj))
each item in obj
+unpackKanji(item)
else
ul
if(obj.children)
li=obj.label
+unpackKanji(obj.children)
else
li=obj.label
+unpackKanji(obj)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question