spu*_*der 2 angularjs angularjs-filter
使用AngularJS,如何在数组中创建项的子集?
例如; 从"todos"创建一个新数组,该数组仅包含"done:true"项.
function fooController ($scope) {
$scope.todos = [
{text:'foo' , done:false},
{text:'foobar' , done:true},
{text:'foofoo' , done:false},
{text:'foobar2' , done:true}
]
}
Run Code Online (Sandbox Code Playgroud)
http://docs.angularjs.org/api/ng.filter:filter
见约10:45 - >结束
只需将过滤器添加到ngRepeat并仅显示您想要的内容:
ng-repeat='todo in todos | filter:done==true'
Run Code Online (Sandbox Code Playgroud)
小提琴:http://jsfiddle.net/dPWsv/1/
如果要从列表中完全删除元素,请使用archive小提琴中的函数.
注意:从版本1.1.3开始,过滤器行为已更改.你现在想要使用
ng-repeat='todo in todos | filter:{done:true}'
Run Code Online (Sandbox Code Playgroud)
小提琴:http://jsfiddle.net/UdbVL/1/