2014-10-10 76 views
0

我有一個列表過濾:如何通過將其保留爲空來重置過濾器?

<input ng-model="searchFileName" /> 
<table> 
    <tr ng-repeat="file in folders | filter:searchFileName"> 
     <td><a ng-click="openFolder(file.name)">{{ file.name }}</a></td> 
    </tr> 
</table> 

我想清楚searchFileName值當我點擊搜索結果。

這是openFolder功能:

$scope.openFolder = function(name) { 
    $scope.searchFileName = null; 

    $http.jsonp($scope.server + '?open=' + encodeURIComponent($scope.buildTreePath()) + '&callback=JSON_CALLBACK').success(function(data){ 
     $scope.folders = data; 
    }); 
} 
} 

我不能空我過濾器領域,這是行不通的......我在哪裏錯了?

+0

儘量把'$ scope.searchFileName = NULL;'成功回調內,臨近'$ scope.folders =數據;' – 2014-10-10 14:06:32

回答

2

只需使用:

$scope.openFolder = function(name) { 

    $scope.searchFileName = null; 
    } 

var app = angular.module('app', []); 
 

 
app.controller('fCtrl', function($scope) { 
 

 
    $scope.folders = [ 
 

 
    { 
 
     name: "Ala" 
 
    }, { 
 
     name: "Ata" 
 
    }, { 
 
     name: "Ara" 
 
    }, { 
 
     name: "Ama" 
 
    } 
 

 
    ]; 
 

 
    $scope.openFolder = function(name) { 
 

 
    $scope.searchFileName = null; 
 
    } 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<div ng-app="app"> 
 
    <div ng-controller="fCtrl"> 
 

 
    <input ng-model="searchFileName" /> 
 
    <table> 
 
     <tr ng-repeat="file in folders | filter:searchFileName"> 
 
     <td><a ng-click="openFolder(file.name)">{{ file.name }}</a> 
 
     </td> 
 
     </tr> 
 
    </table> 
 
    </div> 
 
</div>

+0

我編輯我的問題,因爲也許我認爲jsonp調用更重要。我認爲這就是爲什麼我的結果列表保持爲空,因爲過濾器仍然在應用ajax更新後,也許過濾器的值不能爲空... – emurb 2014-10-10 14:02:23

+0

我可以看到你的解決方案正在工作,但在我的情況。我應該重置過濾結果和篩選字段,但不知道如何處理。 – emurb 2014-10-10 14:04:10

+0

@emurb請看這裏http://jsfiddle.net/oj57g82a/2/它看起來像你的$ http.jsonp不返回任何數據 – sylwester 2014-10-10 15:56:31

相關問題