首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用AMP [AMP-STATE] [AMP-BIND] [AMP-胡须]过滤JSON数据

用AMP [AMP-STATE] [AMP-BIND] [AMP-胡须]过滤JSON数据
EN

Stack Overflow用户
提问于 2018-05-02 18:32:04
回答 1查看 1.1K关注 0票数 1

我正致力于在AMP结构中构建一个库存列表,因为我们站点的其余部分都是用AMP构建的,并且需要能够过滤我的一些数据以便于使用。下面是我目前正在做的工作的链接:库存清单

我一直在使用的产品浏览网页的例子,在AMP通过示例网站作为我的指导方针,如何进行这一点(产品浏览页)。然而,我似乎根本无法让我的数据进行过滤。我希望当我从我的选择菜单中选择“轮式装载机”时,我的库存列表中的项目将消失。

这里是我的初始代码块,它设置了“Machine”选择菜单,我还有另外两个层来进行这个筛选,当我试图让它正常工作时,我已经将其注释掉了。

代码语言:javascript
复制
     <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来填充。

代码语言:javascript
复制
    <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”,但稍后会为其添加功能。

GitHub链接到代码

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-03 15:27:11

看起来,根据提供的Type参数,需要在服务器/API端进行过滤。当类型被更改并在URL中正确设置type时,获取调用在库存列表链接上发生,但在我测试这两种类型时,它返回了相同的JSON。在我看来它的那部分是正确的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50141317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档