过滤数据angularjs后显示消息空结果

时间:2016-01-19 05:41:31

标签: jquery angularjs

我正在使用angularjs创建一个应用程序。我根据过滤器集成了多个过滤器和搜索结果。但是当过滤器没有返回结果时,我无法显示消息没有结果。这是我的代码:

 <div dir-paginate="partners in partnersData|orderBy:orderByField:reverseSort|filter:partners.name|filter:partners.website|filter:partners.location|itemsPerPage: pageSize" current-page="currentPage">
          <div class="rowDiv">
            <div class="cellDiv"><span   ng-click="makeFavourite(partners)" class="star_rating" ng-class="{'select':partners.select}"></span> <span ng-click="showImage($index)"></span></div>
            <div class="cellDiv" ng-click="showName($index)">{{partners.name}}</div>
            <div class="cellDiv">{{partners.website}}</div>
            <div class="cellDiv">{{partners.location}}</div>
            <div class="cellDiv">{{partners.service}}</div>
            <div class="cellDiv">{{partners.connection}}</div>
            <div class="cellDiv">{{partners.action}}</div>
            <div class="cellDiv lastCell"><span class="icon_pluse" ng-click="openPlus($index)"></span><span class="icon_info" ng-click="openInfo($index)"></span></div>
          <div ng-if="partnersData.length === 0">No Items Found</div>
          </div>

2 个答案:

答案 0 :(得分:4)

从角度1.4开始,您可以使用as aliasName为已过滤的数组创建一个别名,该别名将添加到当前范围。重要的是as位于表达式

中的所有过滤器之后
<div dir-paginate="partners in partnersData|orderBy:...|...| lastFilter as filteredArray">

</div>

<!-- Outside paginate directive -->
<div ng-if="!filteredArray.length">No results</div>

答案 1 :(得分:0)

您正在检查partnersData的长度是否为0,如果已过滤则不会发生。 而是将过滤后的项目分配给新变量:

insert or replace into poet (_id,Name, count) values (
   (select _id from poet where Name = "SearchName"),
   "SearchName",
    (select count from poet where Name = "SearchName")+ 1)

然后检查<div ng-repeat="partners in filtered = (partnersData | orderBy:orderByField:reverseSort|filter:partners.name|filter:partners.website|filter:partners.location|itemsPerPage: pageSize)"> </div>