【发布时间】:2016-07-07 01:50:46
【问题描述】:
抱歉标题含糊不清,但这是个含糊不清的问题¯\_(ツ)_/¯
我有 3 个嵌套的 ng-repeats 来表示 Google Analytics(分析)的帐户结构。有几个帐户。每个帐户可以有多个属性,具有多个视图,因此:account -> property -> view。这是前端代码:
<div class="form-group">
<div class="input-group">
<label>Search for an estate by name or ID</label>
<input type="text" class="form-control" ng-model="search" search-box="" />
</div>
</div>
<div ng-repeat="ac in accounts track by ac.id">
<h5>{{ac.name}} — <code>{{ac.id}}</code>
</h5>
<div class="well well-sm">
<div ng-repeat="prop in ac.properties track by prop.id" ng-show="filteredViews.length > 0">
<h6> – {{prop.name}} — <code>{{prop.id}}</code>
</h6>
<ul class="list-group">
<li class="list-group-item" ng-repeat="view in prop.views | viewFilter:search as filteredViews track by view.id">
<label>
<input type="checkbox" checklist-model="selectedEstates" checklist-value="view" /> {{view.name}} — <code>{{view.id}}</code>
</label>
</li>
</ul>
</div>
</div>
</div>
这张图片是使用随机生成的层次结构渲染时的样子。您可以看到,在 2 个帐户下有几个属性,每个属性下都有视图。
上面有一个搜索栏。这个想法是让用户能够通过视图名称或视图 ID 进行搜索。当用户键入时,应仅保留具有匹配视图的帐户和属性。其余的应该隐藏。
但是,在我当前的实现中,我只能隐藏没有匹配子项的属性,不是不匹配的帐户。例如:
我的问题是,如何隐藏没有匹配视图的帐户(孙子)?
PLUNKER:https://plnkr.co/edit/hvicwa5slPJlpGOfoitn?p=preview
【问题讨论】:
-
PS 如果有人对如何使这个问题更简洁有任何建议,我很乐意提供帮助。
标签: javascript angularjs angularjs-ng-repeat angularjs-filter