amp-html - AMP 列表 - 如果我们没有收到 API 的响应,如何删除空白?

标签 amp-html amp-list

我们有 AMP 页面,我们从服务器获取 3 个列表,并将其绑定(bind)到客户端。 Here是同样的 fiddle 。

但是由于输出是动态的并且我们将高度指定为 100,因此在代码 here 中其中第二个列表返回空 json,我们看到很多空白,这是不希望的。

获取空列表的代码是:

<amp-list width="auto" height="100" layout="fixed-height" src="https://ampbyexample.com/json/examples-empty.json" class="m1">
    <template type="amp-mustache" id="amp-template-id">
      <div><a href="{{url}}">{{title}}</a></div>
    </template>
</amp-list

我们如何摆脱这个固定高度的 AMP 列表并根据从服务器接收到的内容调整高度?

我读过类似的内容 here但我无法理解这一点。有人可以分享一下如何解决这个问题吗?

最佳答案

目前 amp-list 无法实现此目的。您可以使用amp-access反而。该方法是在 amp-access authorization 端点中返回 JSON 数据。根据数据,您可以在页面上动态呈现内容:

<section amp-access="items">
  <template amp-access-template type="amp-mustache">
    {{#items}}
    <div><a href="{{url}}">{{title}}</a></div>
    {{/items}}
  </template>
</section> 

关于amp-html - AMP 列表 - 如果我们没有收到 API 的响应,如何删除空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52335233/

相关文章:

reactjs - 类型 'amp-img' 上不存在属性 'JSX.IntrinsicElements'

javascript - 谷歌AMP : How to make an infinite-scroll in AMP?

amp-html - 带有其他选项的放大器下拉菜单

amp-html - AMP 在 Show More 上显示加载指示器

css - amp-story 能否与 Normalize.css 和 Basscss 完全兼容?

google-analytics - 如何重写amp-analytics在Google AMP中报告的页面名称(网址)?

reactjs - 如何在 NextJS 中分离 amp-page 和 not amp-page?

amp-html - 您可以在非 AMP 页面上使用 AMP 标签吗?