我正在尝试做一些类似的事情:
<div ng-controller="TestCtrl">
<div ng-repeat="(k,v) in items | filter:hasSecurityId">
{{k}} {{v.pos}}
</div>
</div>
AngularJs部分:
function TestCtrl($scope)
{
$scope.items = {
'A2F0C7':{'secId':'12345', 'pos':'a20'},
'C8B3D1':{'pos':'b10'}
};
$scope.hasSecurityId = function(k,v)
{
return v.hasOwnProperty('secId');
}
}
但不知何故,它向我显示了所有项目。如何过滤(key,value)?
发布于 2013-02-10 00:13:08
我的解决方案是创建自定义过滤器并使用它:
app.filter('with', function() {
return function(items, field) {
var result = {};
angular.forEach(items, function(value, key) {
if (!value.hasOwnProperty(field)) {
result[key] = value;
}
});
return result;
};
});
在html中:
<div ng-repeat="(k,v) in items | with:'secId'">
{{k}} {{v.pos}}
</div>
发布于 2015-12-10 06:16:24
您还可以在ng-if
中使用ng-repeat
<div ng-repeat="(key, value) in order" ng-if="value > 0">
发布于 2013-10-22 22:07:49
https://stackoverflow.com/questions/14788652
复制相似问题