我试图在angularJS中用ng-重复来修正值.但是当过滤对象是负值(例如-1)时,它被计算为pogitive值(ex.1)。
html:
<div ng-controller="tagCtrl">
<h5>filter object</h5>
<li ng-repeat="cat in categoryToFilter()|filter: filterCategories" >
<span class="cateNm">{{cat.catNm}}</span>
<span ng-repeat="tag in tagCount|filter:{catId : cat.catId}">{{tag.tagNm}}|</span>
</li>
</div>联署材料:
var app = angular.module('app', []);
function tagCtrl($scope){
$scope.tagCount = [
{catId:-1, catNm:"nagativeCategory", tagId:0, tagNm:"Z", count:50},
{catId:1, catNm:"aCategory", tagId:1, tagNm:"A", count:50},
{catId:2, catNm:"bCategory", tagId:2, tagNm:"B", count:30},
{catId:3, catNm:"cCategory", tagId:3, tagNm:"C", count:20}
];
var indexedCategories = [];
$scope.categoryToFilter = function(){
indexedCategories = [];
return $scope.tagCount;
};
$scope.filterCategories = function(cat){
var cateIsNew = indexedCategories.indexOf(cat.catId) == -1;
if(cateIsNew){
indexedCategories.push(cat.catId);
}
return cateIsNew;
};
}产出(不正确):
nagativeCategory Z_x aCategory Z_x_A_A_2 bCategory B cCategory C_x
“z”不应包含在aCategory中。如何正确地过滤负值?
提前谢谢。
小提琴手:http://jsfiddle.net/xVjw6/3/
发布于 2014-03-29 08:00:52
默认情况下,角使用contain运算符作为过滤器。
尝试使用true作为2rd参数,使用angular.equals进行比较
filter:{catId : cat.catId}:true演示
来自文档
是的:
function(actual, expected) { return angular.equals(expected,actual) }的缩写。 这基本上是对预期和实际情况的严格比较。
https://stackoverflow.com/questions/22728550
复制相似问题