角度过滤器无法按预期工作

时间:2016-06-21 12:45:06

标签: javascript jquery angularjs angularjs-ng-repeat angularjs-filter

fiddle

在下面的代码中,它适用于两个过滤器。例如,如果我给出

<li ng-repeat="list in arr | filter:DegreeName='masters'">

<li ng-repeat="list in arr | filter:DegreeName='certificate'">

我得到了预期的结果。可能是一些愚蠢的错误,但我无法弄明白。

HTML

<div ng-controller="MyCtrl">
    <li ng-repeat="list in arr | filter:DegreeName='masters'">
    {{list.Name}}-{{list.DegreeName}} - {{list.DegreeCode}}{{list.URL}}
    </li>
</div>

JS

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

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
alert();
    $scope.arr = [{"URL":"/online-degrees/certificate-nursing-education","NavKey":"certificate-nursing-education","Name":"Nursing Education","AOS":"Nursing","DegreeName":"certificate","DegreeCode":"CERT","LearningFormat":"Structured","DegreeTitle":"Post-Masters Certificate"}];
}

1 个答案:

答案 0 :(得分:3)

您应该指定要以JSON格式匹配的数据。

<li ng-repeat="list in arr | filter: {DegreeName: 'masters'}">

Working Fiddle

如果要过滤那些与文本完全匹配的值,可以将等式检查值传递给true。但正如我所看到的,解决方案的第一部分将适用于您的场景。

<li ng-repeat="list in arr | filter: {DegreeName: 'masters'}: true">