如何在amp-HTML中将对象添加到amp状态数组?
我有一个名为currentItem的状态,带有url、标题、说明。。。当我按下一个按钮时,currentItem应该保存在另一个称为myItems的状态。它将包含项目和对象的列表 现在的问题是,它总是显示最后一项,因此它会覆盖每个currentItem submit的整个列表 我国: { 网址:, imageUrl:, 标题:, 说明: } [] 列表定义: ... 将currentItem添加到列表的操作: 添加 我尝试使用AMP.setState{myItems:myItems.concatcurrentItem},但它也会崩溃,使用+。我该怎么做呢?concat需要一个数组。以下是工作版本:如何在amp-HTML中将对象添加到amp状态数组?,amp-html,amp-list,amp-bind,Amp Html,Amp List,Amp Bind,我有一个名为currentItem的状态,带有url、标题、说明。。。当我按下一个按钮时,currentItem应该保存在另一个称为myItems的状态。它将包含项目和对象的列表 现在的问题是,它总是显示最后一项,因此它会覆盖每个currentItem submit的整个列表 我国: { 网址:, imageUrl:, 标题:, 说明: } [] 列表定义: ... 将currentItem添加到列表的操作: 添加 我尝试使用AMP.setState{myItems:myItems.concat
<amp-state id="currentItem">
<script type="application/json">
{
"url": "url",
"imageUrl": "imageUrl",
"title": "title",
"description": "desc"
}
</script>
</amp-state>
<amp-state id="myItems">
<script type="application/json">
[]
</script>
</amp-state>
<h1>Hello AMPHTML World!</h1>
<amp-list class="mt3" layout="fixed-height" height="0" [src]="myItems" [height]="myItems.length * 200" items="." binding="no">
<template type="amp-mustache">
Item: {{title}}
</template>
</amp-list>
<button type="button" on="tap:AMP.setState({
myItems: myItems.concat([currentItem])
})">
Add
</button>