【发布时间】:2018-11-11 20:34:23
【问题描述】:
我有一个 JSON 对象数组,我试图将列表过滤到仅存在特定字段值的对象。
我要过滤的字段几乎可以包含任何内容,因此除了存在值的位置之外,我无法真正寻找匹配的内容。
我需要在 angularjs 控制器中应用过滤器。
如果我对特定值(如“bob”)进行匹配,则以下内容有效,但并非所有对象都具有“newName”的值。
$scope.CorrectedNames = $filter('filter')($scope.dataList, { newName: 'bob' }).length;
console.log('Total Names to Update: '+$scope.totalCorrectedAccountNumbers.length);
我试过了
newName: '!'
这将返回零个结果。
newName: '!""'
这会返回整个 json 列表
它们是我通过搜索得出的仅有的 2 个想法。
字段值为空且不为NULL,否则我认为以下将起作用。
newName: '!=null'
【问题讨论】:
-
用js过滤器代替$filter怎么样?像 $scope.CorrectedNames = $scope.dataList.filter(x => x.newName === '');
标签: arrays angularjs json filter