amp-list [src] 表达式计算但不触发网络请求

amp-list [src] expression evaluates but doesn't fire network request

我还在习惯 AMP 和表达式,如果这看起来像是一个基本的 qn,我深表歉意!

我需要根据状态是否设置为 <amp-list [src]> 使用稍微不同的 URL。

初始状态:

<amp-state id="selectedStation">
    <script type="application/json">
        {
            "selectedStation": ""
        }
    </script>
</amp-state>

放大器列表表达式:

<amp-list class="mt1" width="auto" height="150px" layout="fixed-height" 
  [src]="selectedStation.selectedStation == '' ? 'deals.json? 
  country=AMP_GEO(ISOCountry)' : 'deals.json? country=AMP_GEO(ISOCountry)&origin=AMP_STATE(selectedStation.selectedStation)'">

使用#development=1 模式,从控制台日志警告中可以看出表达式的计算结果: 默认值 (null) 与 的第一个结果 (deals.json?country=AMP_GEO(ISOCountry)) 不匹配。我们建议编写具有匹配默认值的表达式,但如果有意,可以安全地忽略它。

但是,请求没有被触发。我是不是表达有问题或遗漏了什么明显的东西?

非常感谢!

来自 amp-bind 文档(强调我的):

For performance and to avoid the risk of unexpected content jumping, amp-bind does not evaluate expressions on page load. This means that the visual elements should be given a default state and not rely amp-bind for initial render.

换句话说,由于您只指定了 [src] 而没有指定 src,因此 src 在页面加载时为空,并且 [src] 只会在用户与这一页。您可能希望同时设置它们:

<amp-list
  class="mt1"
  width="auto"
  height="150px"
  layout="fixed-height"
  src="deals.json?country=AMP_GEO(ISOCountry)"
  [src]="selectedStation.selectedStation == '' ? 'deals.json?country=AMP_GEO(ISOCountry)' : 'deals.json? country=AMP_GEO(ISOCountry)&origin=AMP_STATE(selectedStation.selectedStation)'"
>