Ich bin also ein Anfänger hier und probiere aus, eine Web-App basierend auf einem Tutorial zu erstellen. Basierend auf dem, was ich gelernt habe, innerhalb eines Objekts kann ich die Eigenschaft des Objekts mit dem Code this.property-nameVerweis auf die Eigenschaft eines Objekts
Bezug auf die Codes unten arbeiten, nur meine Annahme bestätigen, dass 'this.todos 'wurde als Objekt unten über die Codes erstellt this.todos.push ({ todoText: todoText, abgeschlossen: false, });
und daher kann ich this.todos.property-name, wie this.todos.todoText und this.todos.completed irgendwo innerhalb toDoList Objekt?
Ich weiß nicht, wo ich das durcheinander mache. Vielen Dank, Leute.
var toDoList =
{
todos: [],
displayToDo: function()
{
if (this.todos.length ===0)
{
console.log ("your todos is empty")
}
else
{
console.log('My To Dos:');
for (var i=0; i<this.todos.length; i++)
{
if (this.todos[i].completed === true)
{
console.log ('(x)', this.todos[i].todoText);
}
else
{
console.log ('()', this.todos[i].todoText);
}
}
}
},
addToDo: function(todoText)
{
this.todos.push
({
todoText: todoText,
completed: false,
});
this.displayToDo();
},
changeToDo: function(position, todoText)
{
this.todos[position].todoText = todoText;
this.displayToDo();
},
deleteToDo: function(position)
{
this.todos.splice(position, 1);
this.displayToDo();
},
toggleCompleted: function(position)
{
var todo = this.todos[position];
todo.completed = !todo.completed;
this.displayToDo();
},
toggleAll: function()
{
var totalTodos = this.todos.length;
var completedToDos = 0;
for (var i=0; i<totalTodos; i++)
{
if (this.todos[i].completed === true)
{
completedToDos++;
}
}
if (completedToDos === totalTodos)
{
for (var i=0; i<totalTodos; i++)
{
this.todos[i].completed = false;
}
}
else
{
for (var i=0; i<totalTodos; i++)
{
this.todos[i].completed = true;
}
}
this.displayToDo();
}
};