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)
},
I would like to ask how the filteredTodos method calls the filters method to have an array? What is the usage? Please solve your doubts~
大家讲道理2017-05-19 10:20:18
filters[this.visibility]
This is not an array, but a method under the calling object.
this.visibility
的结果可能有三个 all
, active
, completed
So it ends up being something like this:
filters['all']
就相当于调用了 filters
对象下的 all
方法,因为 this.visibility
is a variable, so it must be written like this