Javascript – JS-Funktionsproblem
黄舟
黄舟 2017-05-19 10:18:18
0
1
355
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~

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

Antworte allen(1)
大家讲道理

filters[this.visibility] 这里不是数组,是调用对象下的方法。

this.visibility的结果可能有三个 all, active, completed 所以最终是个类似于这样的东西:

filters['all'] 就相当于调用了 filters 对象下的 all 方法,因为 this.visibility 是个变量,所以必须写成这种写法

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!