angularjs:检查ng-repeat中过滤器的长度

时间:2015-06-26 08:15:48

标签: javascript html angularjs

例如我有这个重复列表:

$.getJSON("/svrBooking/json/getEmployeesByManager",{
            "manager": "Paul Walker",
            "endDate": endDate,
            "startDate": startDate,
            "ajax": 'true'
            }, function (result) {...});

我可以以某种方式(如果没有更改控制器会更好,因为它是一个指令)检查:如果过滤结果不为空 - 然后显示整个<ul> <li class="suggestion-item" ng-repeat="item in suggestionList.items | filter: {id: 2} track by track(item)">{{item.text}}</li> <ul> ,如果没有,则隐藏ul。我的意思是:

ul

2 个答案:

答案 0 :(得分:2)

您可以将过滤结果分配给变量

<ul ng-show="filterResult && filterResult.length">
    <li class="suggestion-item" ng-repeat="item in filterResult = (suggestionList.items | filter: {id: 2}) track by track(item)">{{item.text}}</li>
<ul>

答案 1 :(得分:0)

使用 $ parent 即可实现

<ul ng-show="suggestionListItem.length" >
 <li class="suggestion-item" ng-repeat="item in ($parent.suggestionListItem = (suggestionList.items | filter: {id: 2} track by track(item)))">{{item.text}}</li>
<ul>