【问题标题】:How to show/hide a UI component based on "|filter" results in AngularJS?如何在 AngularJS 中根据“|filter”结果显示/隐藏 UI 组件?
【发布时间】:2016-02-02 22:17:08
【问题描述】:

我有一个嵌套表结构,其中一个表基于 Javascript 对象“metasetHashSplit”的 ng-repeat 填充,而该表又具有一个基于名为“ids”的属性填充的表。如果内部表中的所有元素都被过滤掉,我需要隐藏主要的 ng-repeat。我正在使用“管道”/“|”过滤内部表。 我无法根据是否过滤掉内部表中的所有记录来确定何时或如何触发 ng-show/hide。

代码是这样设置的:

<tbody  ng-repeat="(metaset, ids) in metasetHashSplit">
<tr class = "meta">
    <td   rowspan = 100 >{{metaset}}</td>
</tr>
<tr class = "meta" style="margin:0;padding:0;"  ng-repeat="item in ids" >
    <td class = "innerTable">
        <table class="table  child table-hover table-bordered table-condensed " >
            <tr ng-repeat="buy in item.Buy  | filter:{ MBC: by_buyMBC }" >
                <td >{{buy.BuyId}}</td>
                <td >{{buy.BuyRelease}}</span></td>
                <td >{{buy.BuyComponentAffected}}</td>
                <td >{{buy.BuyStatus}}</span></td>
            </tr>
        </table>
    </td>
</tr>

如果他们发现自己处于这样的位置,可以帮助我吗?基本上,tbody 需要根据 |filter:{MBC:by_buyMBC} 结果显示/隐藏!

【问题讨论】:

    标签: javascript angularjs ng-repeat angular-filters ng-show


    【解决方案1】:

    基于this question 使用:

    <div ng-repeat="buy in filtered = (item.Buy | filter:{ MBC: by_buyMBC })">
    </div>
    

    因此,您所要做的就是在正确的元素上使用 ng-if="filtered.length &gt; 0" 来显示和隐藏

    【讨论】:

    • 这太棒了。我怎么会错过这个!谢谢,试试这个看看。
    • 我也错过了它,直到有一天我需要它 - 然后不得不像个坏孩子一样谷歌:D
    • 看起来嵌套的 ng-repeats 的范围可能会导致很多复杂性。例如,var“filtered”没有被父 ng-repeat 循环识别,需要根据“filtered”显示/隐藏
    • 在这种情况下,您可能必须使用$filter 在控制器上进行过滤,然后将其绑定到$scope.filteredBuyList 之类的东西上
    • 考虑一下,您可以尝试一些厚脸皮的事情并做一些类似buy in item.filtered = (item.buy | ... 的事情,然后看看您是否可以绑定到那个
    猜你喜欢
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 2011-03-11
    相关资源
    最近更新 更多