0
需要以下模板的幫助來整理給定的json數據。裏面的每個對象都是另一個命名對象,有沒有辦法簡單地遍歷列表。小鬍子模板與具有一系列命名對象的對象一起使用
到目前爲止找不到處理這種情況的示例。請幫助。
{
"6gb1": {
"id": "b7e3b34b-7f15-4221-9601-69899a29c738",
"productId": "6gb1",
"title": "Social Studies",
"folioNumber": "1",
"publicationDate": "2014-01-10T05:00:00.000Z",
"targetDimensions": ["1024x768"],
"folioDescription": "Social Studies",
"manifestXRef": "Social Studies",
"previewImageURL": "",
"isFree": true
},
"5gb2": {
"id": "65017770-bd01-47a2-867b-46948ea58d4c",
"productId": "5gb2",
"title": "Algebra",
"folioNumber": "1",
"publicationDate": "2014-01-10T05:00:00.000Z",
"targetDimensions": ["1024x768"],
"folioDescription": "Algebra",
"manifestXRef": "Algebra",
"previewImageURL": "",
"isFree": true
},
"5gb1": {
"id": "b1148439-1b18-4b63-8d92-b3a4051286af",
"productId": "5gb1",
"title": "English",
"folioNumber": "1",
"publicationDate": "2014-01-10T05:00:00.000Z",
"targetDimensions": ["1024x768"],
"folioDescription": "English",
"manifestXRef": "English",
"previewImageURL": "",
"isFree": true
},
"6gb2": {
"id": "0199ac64-3f20-45f9-ba70-883f95ab0e58",
"productId": "6gb2",
"title": "Environmental Science",
"folioNumber": "1",
"publicationDate": "2014-01-10T05:00:00.000Z",
"targetDimensions": ["1024x768"],
"folioDescription": "Environmental Science",
"manifestXRef": "Environmental Science",
"previewImageURL": "",
"isFree": true
}
}
和模板
<script id="folioTemplate" type="text/template">
{{#folios}}
<li class='folio clearfix'>
{{folioDescription}}
<div id='title'>{{{title}}}</div>
</li>
{{/folios}}
</script>
和腳本是
document.getElementById("folios").innerHTML = Mustache.render(document.getElementById('folioTemplate').innerHTML, {'folios': folios});