首页 > 解决方案 > 在加载时使用 amp-bind 或 amp-state 初始化 amp-list

问题描述

我们正在使用 express + EJS 引擎。我想使用 amp-state 和 amp-bind 使用包含 amp-list 项的 EJS 变量初始化我的 amp-list。搜索后我意识到: amp-bind 表达式不会在页面加载时进行评估。但我需要它。我怎样才能拥有一个带有初始化项目和无限加载更多功能的放大器列表?

<amp-state id="localState">
  <script type="application/json">
    {
      "items": [{"id": 1}, {"id": 2}, {"id": 2}]
    }
  </script>
</amp-state>
<amp-list src="amp-state:localState">
  <template type="amp-mustache">
    <li>{{id}}</li>
  </template>
</amp-list>

此列表在加载时没有任何项目。

标签: expressejsamp-html

解决方案


推荐阅读