我有如下数据:
[
{ id: 1, name: 'test', point: '2000' },
{ id: 2, name: 'bob', point: '1000' },
{ id: 3, name: 'hello', point: '3000' },
{ id: 4, name: 'xx', point: '4000' },
{ id: 5, name: 'zz', point: '1000' },
{ id: 2, name: 'fad', point: '1000' }
]
如何动态地过滤不同点而不是静态过滤:
<div ng-repeat="item in items | filter: { point: '1000' }">
<div ng-repeat="item in items | filter: { point: '2000' }">
答案 0 :(得分:0)
您可以在作用域上创建一个点对象并在控制器中更新它,而不是静态值,而是使用作用域对象。
代码相同:
控制器:
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.items = [
{ id: 1, name: 'test', point: '2000' },
{ id: 2, name: 'bob', point: '1000' },
{ id: 3, name: 'hello', point: '3000' },
{ id: 4, name: 'xx', point: '4000' },
{ id: 5, name: 'zz', point: '1000' },
{ id: 2, name: 'fad', point: '1000' }
]
$scope.pointToBeFiltered = '3000';
});
HTML:
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<div ng-repeat="item in items | filter: { point: pointToBeFiltered }">{{item}}</div>
</body>