我正在尝试实现amp-list来允许不同的货币,这取决于用户来自哪里。我已经实现了amp-list元素,并创建了一个JSON文件(这是一个CORS url),其中包含使用正确语法的数据。
然而,amp-list并没有打印数据,而是打印了一个空格。HTML模板为:
<amp-list width="auto"
height="50"
layout="fixed-height"
src="/amp-price/57938">
<template type="amp-mustache">
<p class="price align-center {{test}}">{{price}}</p>
</template>
</amp-list>而JSON响应是:
{"items": [{"price": "\u00a321.59", "test": "test"}]}但是呈现的HTML是:
<amp-list width="auto" height="50" layout="fixed-height" src="/amp-price/57938" class="i-amphtml-element i-amphtml-layout-fixed-height i-amphtml-layout-size-defined i-amphtml-layout" aria-live="polite" style="height: 50px;">
<template type="amp-mustache">
<p class="price"> - </p>
</template>
<div class="i-amphtml-fill-content i-amphtml-replaced-content" role="list"></div></amp-list>JSON响应具有所有正确的AMP标头,并且我在控制台中没有收到任何AMP错误。
我还跟踪了页面源代码中的src链接,它指向了正确的URL。
我是不是漏掉了什么简单的东西?
发布于 2019-06-18 21:08:06
我也有同样的问题,我几乎什么都试过了。Safari10中的amp-list不会加载json端点。
但我的解决方案是将credentials="include"添加到我的amp-list标记中:
最终的amp-list
<amp-list credentials="include" id="smallcartsList" width="auto" height="@HeightRequest" [height]="CurrentCartList.items.length == 0 ? 5 : 50 * CurrentCartList.items.length" media="(max-width: 1199px)" layout="fixed-height" binding="no" src="/API/CartList/GetCartsList" [src]="cartlistsource" template="cartlistdetail"> </amp-list>发布于 2018-03-12 12:37:09
Sebastian Benz是正确的,我使用了相同的代码,并且工作正常
头JS
<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.1.js"></script>BODY HTML
<amp-list width="auto"
height="50"
layout="fixed-height"
src="https://jsonblob.com/api/jsonBlob/1f6f838d-25aa-11e8-8863-d99090d9ec78">
<template type="amp-mustache">
<p class="price align-center {{test}}">{{price}}</p>
</template>
</amp-list>https://stackoverflow.com/questions/49196633
复制相似问题