vue 2过滤多个数组

时间:2017-08-30 04:55:20

标签: javascript json vuejs2

对不起,我的json数据有两个数组。

我想用Vue.js过滤这个json数据(banner_img:['img'])。

但分析Json数据是一些问题..

Json数据

[{"id":10,"banner":"AIR","banner_img":[{"id":1,"img":"air_1.png","banner_id":10},{"id":2,"img":"air_2.png","banner_id":10}]},
{"id":11,"banner":"HOT","banner_img":[{"id":3,"img":"hot_1.png","banner_id":11},{"id":4,"img":"hot_2.png","banner_id":11}]},
{"id":12,"banner":"NEW","banner_img":[{"id":5,"img":"new_1.png","banner_id":12},{"id":6,"img":"new_2.png","banner_id":12}]}]

Vue.js

var app = new Vue({
el: '#app',
data: {
    banner:[],
    search:'',
},
methods: {
    getBannerData: function() {
        axios.get('/case/ajax/33').then(response => {
            this.banner = response.data.banner;
        });
    },
},
mounted: function() {
   this.getBannerData();
},
computed: {
    filteredList() {
      return this.banner(value => {
        return value.banner_img.filter(bannerImg => {
        return bannerImg.img.toLowerCase().includes(this.search.toLowerCase());
        });
      })
    }
}
});

HTML

<input type="text" name="ImgFilter" v-model="search">
<div v-for="value in filteredList">
    <img v-for="imgs in value.banner_img" :src="imgs.img" height="100">
</div>

然后我尝试这个filteredList

return value.banner_img.filter(bannerImg => {
       return bannerImg.img.toLowerCase().includes(this.search.toLowerCase());
});

但不起作用..

请给我一些建议〜!

1 个答案:

答案 0 :(得分:1)

试试这个:

for