2
I have a list of tasks. The list starts with unfinished tasks (task.done == false) first followed by completed tasks. However, when I select a task and select it as completed (task.done=true), I would like the list to be dynamically ordered and this task to go to the end of the list. Below is the example of my view controller.
app.controller ('crtl', function ($scope) {
$scope.tasks = [
{ "task":"task1", "done": false},
{ "task":"task2", "done": true},
{ "task":"task3", "done": false}
];
$scope.tasks.sort(order);
function order (x, y) {
return (x.done === y.done)? 0 : x? 1 : -1;
};
$scope.setDone = function (task) {
task.done = true;
//Como ordernar a lista dinamicamente ao alterar o booleano?
//Esta maneira não funciona
$scope.tasks.sort(order);
};
});