我正在使用多个小胡子部分文件(页眉、页脚、卡片等)渲染我的 amp 页面。在我的一个部分中,我想遍历 JSON 中给出的一组项目,所以我在其中使用 amp-list,我正在使用 amp-mustache 模板。在输出中,我得到了带有空文本的列表。小胡子变量(url 和标题)未解析为 JSON 中给定的值。
我的部分.html
<ul>
<amp-list width="auto" height="100" layout="fixed-height" src="https://ampbyexample.com/json/examples.json" class="m1">
<template type="amp-mustache" id="amp-template-id">
<li><a href="{{url}}">Link - {{title}}</a></li>
</template>
</amp-list>
</ul>
和我的examples.json
{
"items": [
{
"title": "amp-carousel",
"url": "/components/amp-carousel/"
},
{
"title": "amp-img",
"url": "/components/amp-img/"
},
{
"title": "amp-ad",
"url": "/components/amp-ad/"
},
{
"title": "amp-accordion",
"url": "/components/amp-accordion/"
}
]
}
这是我的 index.html
<!doctype html>
<html ⚡ lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="author" content="Uxmint" href=""/>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>Example</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link rel="canonical" href="{{{projectUrl}}}" />
<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
</head>
<body>
{{> partial}}
</body>
</html>