如果子项为空,则隐藏父项

时间:2014-09-19 04:40:04

标签: angularjs

如果子li为空,我想隐藏父li。以下是我要隐藏父li标签TWO的jsfiddle link

<ul id='ListNav'>
    <li ng-repeat='mainList in lists.list' ng-hide='subList.length<0' >
        <a>{{mainList.label}}</a>
        <ul>
            <li ng-repeat='subList in mainList.subList'>{{subList.label}}</li>
        </ul>
    </li>
</ul>

2 个答案:

答案 0 :(得分:0)

要解决此问题,只需更改:

<li ng-repeat='mainList in lists.list' ng-hide='subList.length<0' >

<li ng-repeat='mainList in lists.list' ng-show="mainList.subList.length>0" >

Demo

答案 1 :(得分:0)

您无法在该级别使用subList尝试将其更改为mainList.subList

<ul id='ListNav'>
        <li ng-repeat='mainList in lists.list' ng-hide='mainList.subList.length==0'> <a>{{mainList.label}}</a>

            <ul>
                <li ng-repeat='subList in mainList.subList'>{{subList.label}}</li>
            </ul>
        </li>
    </ul>

http://jsfiddle.net/nepfw2qf/7/