首页 > 解决方案 > 将状态映射到 amp-list [src]

问题描述

我需要使用状态作为 amp-list 的输入。但在此之前,我想映射状态(执行一些数学或运算)。

将数组的每个位置映射到一个对象并将其放入 src 时,我无法使其工作(此处的代码):

<amp-list [src]="menu.array.map(x => ({size_new: x.size.toUpperCase(), color_new: x.color.toUpperCase()}))" width="auto" height="100">
  <template type="amp-mustache">
    <div>
        {{size_new}} // {{color_new}}
    </div>
  </template>
</amp-list>

但是,如果我将每个数组位置映射到一个数组中(此处的代码),我可以使它工作:

<amp-list [src]="menu.array.map(x => [x.size.toUpperCase(), x.color.toUpperCase()])">
  <template type="amp-mustache" width="auto" height="100">
    <div>
        {{0}} // {{1}}
    </div>
  </template>
</amp-list>

有什么建议么?谢谢!

标签: amp-htmlamp-listamp-bind

解决方案



推荐阅读