这是我的JSON文件的一部分
{
"topic": {
"topicTitle": "Living things and the environment",
"subTopics": [
{
"subTopicTitle": "Identifying, namimg and classifying",
"subTopicShortName": "identifyingNamingClassifying",
"subTopicDescription": "About one and a half million kinds of organisms have been discovered. How do we identify, name and classify them?",
"subTopicQuestions": [
{
"question": "Use the key to identify the plants a to e in picture 1.",
"subTopicQuestionAssetLinks": [
"href://file/filename/image1.jpeg"
],
"subTopicQuestionAssetCaptions": [
"Caption 1"
]
},
这是我的javascript
<script>
$.getJSON('data.json', function(data1) {
intro_template = "<h1> {{topic.topicTitle}} </h1> <h2> {{topic.subTopics}} </h2>";
html = Mustache.to_html(intro_template, data1);
$('.intro_template_container').html(html);
});
</script>
h1完美地展示了“生物与环境”
在H2标签之间我想展示“识别,命名和分类”的“subTopicTitle”
这怎么可能?
答案 0 :(得分:1)
由于subTopics
是一个数组,你必须使用胡子部分:
<h1>{{topic.topicTitle}}</h1>
{{#topic.subTopics}}
<h2>{{subTopicTitle}}</h2>
{{/topic.subTopics}}