首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >amp-list不打印从连接的JSON文件返回的数据

amp-list不打印从连接的JSON文件返回的数据
EN

Stack Overflow用户
提问于 2018-03-09 23:06:55
回答 2查看 1K关注 0票数 0

我正在尝试实现amp-list来允许不同的货币,这取决于用户来自哪里。我已经实现了amp-list元素,并创建了一个JSON文件(这是一个CORS url),其中包含使用正确语法的数据。

然而,amp-list并没有打印数据,而是打印了一个空格。HTML模板为:

代码语言:javascript
复制
<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响应是:

代码语言:javascript
复制
{"items": [{"price": "\u00a321.59", "test": "test"}]}

但是呈现的HTML是:

代码语言:javascript
复制
<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。

我是不是漏掉了什么简单的东西?

EN

回答 2

Stack Overflow用户

发布于 2019-06-18 21:08:06

我也有同样的问题,我几乎什么都试过了。Safari10中的amp-list不会加载json端点。

但我的解决方案是将credentials="include"添加到我的amp-list标记中:

最终的amp-list

代码语言:javascript
复制
<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>
票数 1
EN

Stack Overflow用户

发布于 2018-03-12 12:37:09

Sebastian Benz是正确的,我使用了相同的代码,并且工作正常

头JS

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49196633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档