angular.js - 关于angularjs中自定义filter的问题
大家讲道理
大家讲道理 2017-05-15 16:58:57
0
2
501

刚刚在看angularjs的todoMVC项目,发现它在控制器中自定义了一个过滤器

$scope.$watch('TC.location.path()',function (path) {
            TC.Filters = {'/active':{completed: false},'/completed':{completed:true}}[path];
        });

之后在视图中

<li ng-repeat="todo in TC.todos | filter:TC.Filters track by $index" ng-class="{completed: todo.completed, editing: todo === TC.editedTodo}">

我的问题主要是第一段代码这种写法不了解

function (path) {
            TC.Filters = {'/active':{completed: false},'/completed':{completed:true}}[path];
        }

这个方法中传入path后根据path选择不同的过滤器。

我想问问有没有文档是介绍这种在过滤器对象内选择的写法的。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
伊谢尔伦

Although the reason has been given upstairs, I guess you don’t quite understand it. Let me give you a document to see what $watch is. The document is here.

阿神
$scope.$watch('TC.location.path()',function (path) {
    TC.Filters = {'/active':{completed: false},'/completed':{completed:true}}[path];
});

The change of the path is monitored here. When the path changes, the parameters of the filter also change. In fact, it is the switching between completed and active data

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!