如何在AngularJs中使用ng-repeat过滤(键,值)?我想做的事情如下:<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');
}}但不知何故,它向我展示了所有项目。如何过滤(键,值)?
3 回答
三国纷争
TA贡献1804条经验 获得超7个赞
我的解决方案是创建自定义过滤器并使用它:
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>
慕运维8079593
TA贡献1876条经验 获得超5个赞
你也可以使用ng-repeat具有ng-if:
<div ng-repeat="(key, value) in order" ng-if="value > 0">
添加回答
举报
0/150
提交
取消
