【问题标题】:amp-list not printing returned data from the connected JSON fileamp-list 不打印从连接的 JSON 文件返回的数据
【发布时间】:2023-04-06 01:40:01
【问题描述】:

我正在尝试实施 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。

我缺少一些简单的东西吗?

【问题讨论】:

  • 您可以添加指向示例页面的链接吗?另一件事:您是否在标头中导入 amp-mustache 扩展?
  • @DHiskett 检查我的答案希望这对你有帮助。

标签: json amp-html


【解决方案1】:

我遇到了同样的问题,我几乎尝试了所有方法。 safari 10 中的 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>

【讨论】:

    【解决方案2】:

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

    Here is working url

    HEAD 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>
    

    正文 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>
    

    JSON DATA LINK

    【讨论】:

    • 感谢您的回复,我在 head 中加载了 amp-list 和 amp-mustache 脚本,烦人的是我的代码与 jsfiddle 中的代码相同,但似乎仍然无法正常工作。不幸的是,我无法分享我正在尝试的页面,因为它位于我们的暂存环境中。你有什么想法吗?
    • 可能是url问题,应该是https
    • URL 是 https(AMP 页面和 JSON URL)。我也尝试将其更改为绝对 URL,但没有运气
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    相关资源
    最近更新 更多