var filters = {
all: function (todos) {
return todos
},
active: function (todos) {
return todos.filter(function (todo) {
return !todo.completed
})
},
completed: function (todos) {
return todos.filter(function (todo) {
return todo.completed
})
}
}
filteredTodos: function () {
return filters[this.visibility](this.todos)
},
Ich würde gerne fragen, wie die filteredTodos-Methode die filter-Methode aufruft und es ein Array gibt? Was ist die Verwendung? Finden Sie es heraus~
filters[this.visibility]
这里不是数组,是调用对象下的方法。this.visibility
的结果可能有三个all
,active
,completed
所以最终是个类似于这样的东西:filters['all']
就相当于调用了filters
对象下的all
方法,因为this.visibility
是个变量,所以必须写成这种写法