我正致力于在AMP结构中构建一个库存列表,因为我们站点的其余部分都是用AMP构建的,并且需要能够过滤我的一些数据以便于使用。下面是我目前正在做的工作的链接:库存清单。
我一直在使用的产品浏览网页的例子,在AMP通过示例网站作为我的指导方针,如何进行这一点(产品浏览页)。然而,我似乎根本无法让我的数据进行过滤。我希望当我从我的选择菜单中选择“轮式装载机”时,我的库存列表中的项目将消失。
这里是我的初始代码块,它设置了“Machine”选择菜单,我还有另外两个层来进行这个筛选,当我试图让它正常工作时,我已经将其注释掉了。
<amp-state id="inventory">
<script type="application/json">
{
"Type": "all",
"listSrc": "https://www.craigattachments.com/json/inventory.json?Type=all&_=RANDOM"
}
</script>
</amp-state>
<amp-list height="60" layout="fixed-height" src="https://www.craigattachments.com/json/inv-dropdowns.json">
<template type="amp-mustache">
<label for="Type">Machine Type</label>
<select id="Type" name="Type" class="inv-dropdown" on="change:AMP.setState({inventory: {Type: event.value,listSrc: 'https://www.craigattachments.com/json/inventory.json?Type='+ event.value +'&_=RANDOM'}})">
<option value="all">Select your machine type</option>
{{#type}}
<option value="{{name}}">{{name}}</option>
{{/type}}
</select>
</template>
</amp-list>然后,我尝试使用上面的代码来过滤我的列表(下面),它是使用我的inventory.json文件填充的。为了测试目的,我缩短了文件,但是它最终将通过我们的ERP系统API来填充。
<amp-list width="auto" height="150" layout="fixed-height" src="https://www.craigattachments.com/json/inventory.json?Type=all&_=RANDOM'" [src]="inventory.listSrc">
<template type="amp-mustache">
<div class="inv-list-row">
<div class="inv-list-item inventory">{{SerialNo_SerialNumber}}</div>
<div class="inv-list-item inventory">{{Part_PartNum}}</div>
<div class="inv-list-item inventory">{{Part_PartDescription}}</div>
<div class="inv-list-item inventory">{{Part_CommercialBrand}}</div>
<div class="inv-list-item inventory">{{Part_CommercialSubBrand}}</div>
<div class="inv-list-item inventory">{{Type}}</div>
</div>
</template>
</amp-list>对我可能缺少的东西有任何见解,这样就可以在选择菜单的变化中过滤我的数据了吗?我假设这是对我的JSON数据中的“Type”项的引用问题,但不知道如何进行连接。
编辑:2018年5月16日
终于起作用了。决定暂时删除“Model”,但稍后会为其添加功能。
发布于 2018-05-03 15:27:11
看起来,根据提供的Type参数,需要在服务器/API端进行过滤。当类型被更改并在URL中正确设置type时,获取调用在库存列表链接上发生,但在我测试这两种类型时,它返回了相同的JSON。在我看来它的那部分是正确的。
https://stackoverflow.com/questions/50141317
复制相似问题