鍍金池/ 問答/HTML/ 兩層v-for循環(huán)時,控制內(nèi)部元素v-show為false時,如何使外層也為fa

兩層v-for循環(huán)時,控制內(nèi)部元素v-show為false時,如何使外層也為false?

<div v-for="(item,index) in out">
    <h1 v-for="(good,index) in item.goods" v-show="good.count>0">{{good.name}}</h1>
</div>

當good.count>0時渲染h1,所有good的count都<0,如何控制外層的div也不顯示?

 out:[
    {
        goods:[
            {name:"test1",count:0},
            {name:"test2",count:0},
            {name:"test3",count:0},
        ]
    },
    {
        goods:[
            {name:"test3",count:0},
            {name:"test4",count:0},
            {name:"test5",count:0},
        ]
    }
]
回答
編輯回答
巴扎嘿
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="box">
            <div v-for="(item,index) in out" v-show="thisshow(item)">
                    <h1 v-for="(good,index) in item.goods" v-show="good.count>0">{{good.name}}</h1>
                </div>
    </div>
   <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>

var app=new Vue({
    el:'#box',
    data:{
        out:[
    {
        goods:[
            {name:"test1",count:0},
            {name:"test2",count:0},
            {name:"test3",count:0},
        ]
    },
    {
        goods:[
            {name:"test3",count:0},
            {name:"test4",count:0},
            {name:"test5",count:0},
        ]
    }
]
    },
    methods: {
        thisshow:function(item){
            var flag = false;
            item.goods.map(function(s){
                if(s.count>0){
                    flag = true;
                };
            });
            return flag;
        }
    }
});
    </script>
</body>
</html>
2017年8月25日 22:27