我已经开始在一个小型 Web 项目中使用 JSON 数据结构而不是 XML。我需要对数据进行一些转换,就像您通常在 XML 上使用 XSLT 所做的那样,然后我偶然发现了很酷的库http://tempojs.com。
但是当我意识到我的数据是一个树形结构时,真正的问题出现了,我想在转换中需要一些递归。
这是数据结构的示例:
[
{
"text" : "The sun is shining",
"children" : []
},
{
"text" : "it's cloudy.",
"children" :
[
{
"text" : "It's raining.",
"children" : []
},
{
"text" : "The sun was shining.",
"children" : []
},
{
"text" : "A rainbow appeared.",
"children" :
[
{
"text" : "A pot of gold was found at the end of the rainbow.",
"children" : []
},
{
"text" : "The gold returned more than a million dollars, when sold.",
"children" : []
}
]
}
]
}
]
我想转换成这样的嵌套 HTML 列表:
<ul>
<li>The sun is shining</li>
<li>it's cloudy.
<ul>
<li>It's raining.</li>
<li>The sun was shining.</li>
<li>A rainbow appeared.
<ul>
<li>A pot of gold was found at the end of the rainbow.</li>
<li>The gold returned more than a million dollars, when sold.</li>
</ul>
</li>
</ul>
</li>
</ul>
任何想法如何使用 Tempo 来完成?