我正在获取我想在HTML页面上呈现的嵌套JSON对象。对象的长度和内容可以变化,我想展示它的一部分。我不知道如何使用Mustache.js
我的对象如下:
{ "success": [
{
"stopID": "123",
"stopName": "ABC",
"lines": [
{
"lineRef": "3",
"destinationID": "987",
"destinationName": "DEF",
"arrivals": [
1490279520000,
1490279460000,
1490280180000
]
}
]
},
{
"stopID": "331",
"stopName": "TVC",
"lines": [
{
"lineRef": "3",
"destinationID": "128",
"destinationName": "NJH",
"arrivals": [
1490279160000,
1490280180000
]
},
{
"lineRef": "3V",
"destinationID": "361",
"destinationName": "KOI",
"arrivals": [
1490280360000
]
}
]
},
{
"stopID": "3601",
"stopName": "LKG",
"lines": [
{
"lineRef": "3",
"destinationID": "128",
"destinationName": "ABC",
"arrivals": [
1490279040000,
1490280360000,
1490280180000,
1490280180000
]
}
]
}
]}
我想显示最多两次到达,我该如何设置限制。
我找到this,但没有多大帮助。我的代码是这样的:
<script id="#timetables" type="text/template">
{{#success}}
<tr style = "">
<th colspan="3" style="padding-left:25px;">{{stopName}}<span><sup style="padding-left:5px;font-weight:100"><small>{{stopID}}</sup></span></th>
</tr>
{{#lines}}
<tr class="line-row">
<td class="" style="border:none;width:10%;">{{lineRef}}</td>
<td class="" style="border:none;width:30%;">{{destinationName}}</td>
<td class="" style="border:none;width:60%;">{{arrivals}}</td>
</tr>
{{/lines}}
{{/success}}
</script>