<table class="col-md-12">
<th>values</th>
<tr>
<td>
<span ng-repeat="item in items">
<span ng-repeat="subitem in item.allowitems" ng-if "item.allowid = 1">
<span ng-repeat="point in subitem.points">{{point.value}}</span>
</span>
</span>
</td>
</tr>
<tr>
<td>
<span ng-repeat="item in items">
<span ng-repeat="subitem in item.allowitems" ng-if "item.allowid = 3">
<span ng-repeat="point in subitem.points">{{point.value}}</span>
</span>
</span>
</td>
</tr>
<tr>
<td>
<span ng-repeat="item in items">
<span ng-repeat="subitem in item.allowitems" ng-if "item.allowid = 5">
<span ng-repeat="point in subitem.points">{{point.value}}</span>
</span>
</span>
</td>
</tr>
</table>
如果point.value为null或者item.allowid为null,我想隐藏相应的行trs。但是我如何在父对象tr中检查ng-if或ng-hide
答案 0 :(得分:0)
可能有更优雅的方法,但一个选项是使用指令隐藏父.closest()
。由于jqLite没有.hide()
或.directive('hideParent', function(){
return {
restrict: 'E',
link: function(scope, element, attrs){
element.closest('tr').hide();
}
}
})
,因此您必须包含对jQuery的引用才能生效。
<tr>
然后,当您想要隐藏父<span ng-repeat="item in items">
<hide-parent ng-if="item.allowid === null"></hide-parent>
<span ng-repeat="subitem in item.allowitems" ng-if="item.allowid === 1">
<span ng-repeat="point in subitem.points">
{{point.value}}
<hide-parent ng-if="point.value === null"></hide-parent>
</span>
</span>
</span>
:
ng-repeat
有些人可能会认为这是解决问题的黑客或肮脏方法,因为除了操作DOM之外,你包含的元素没有任何意义。您可以随时将其更改为包含hideParent
的元素的属性,但是您必须移动确定是否将父项隐藏到<nav>
<a href="">HTML</a>
<a href="">CSS</a>
<a href="">JS</a>
</nav>
指令中的逻辑。