2017-07-15 109 views
0

我試圖根據篩選器的值顯示和隱藏頁面的某些部分。如果數據的長度爲1某個字段應該顯示,如果其等於零,當腳本被執行沒有出現在頁面的不同部分應該顯示使用篩選器的結果根據值顯示視圖

<div ng-show="results.length=0"> 
    <h4 class="redtext" align="center">Sorry, Search found no records </h4> 
</div> 
<div ng-show="results.length!=0" ng-repeat="item in record | dateRange : from : to"> 
    <table width="100%" border="0" cellspacing="5" cellpadding="5"> 
    <tr> 
     <td width="70%"><div align="left"> 
     <p><strong>Bill Period</strong>  </p> 
     </div></td> 
     <td width="82%">{{item.Date |date: 'MMMM yyyy'}}</td> 
    </tr> 
    <tr> 
     <td><p><strong>Reading Date</strong></p></td> 
     <td>{{item.Date |date: 'dd MMMM yyyy'}}</td> 
    </tr> 
    <tr> 
     <td colspan="2">&nbsp;</td> 
    </tr> 
    </table> 

JS

$scope.state_request = function() { 
$http.post("http://localhost/server/statement.php", { 
    'id': $scope.account_number 
}).success(function(data) { 
    console.log(JSON.stringify(data)); 
    $scope.record = data; 
}) 
$scope.from = $filter('date')($scope.sdate, "yyyy-MM-dd" + 'T00:00:00') + 'Z'; 
$scope.to = $filter('date')($scope.edate, "yyyy-MM-dd" + 'T00:00:00') + 'Z'; 
} 
}) 
.filter('dateRange', function() { 
    return function(records, from, to) { 
     // return empty array if input not defined or not array 
     if (!records || !angular.isArray(records)) { 
      return []; 
     } 
     var results = records.filter(function(record) { 
      // run console log tests here...before the return 
      return record.Date >= from && record.Date <= to; 
     }); 
     if (results.length = 0) { 
      console.log('its empty') 
     } else { 
      console.log('results found') 
     } 
     console.log('Number of results:', results.length); 
     return results; 
    } 
}) 

回答

0

如果我清楚地瞭解你,as resultsfilter(在你的情況:ng-repeat="item in record | dateRange : from : to as results")後,將幫助:

而且你做的條件錯字