Skip to content

Commit a83f552

Browse files
committed
fixed rendering after activation of item
1 parent f317698 commit a83f552

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

index.html

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ <h2>{{todoTitle}} </h2>
2222
<div class="todolists">
2323
<ul class="small-box">
2424
<li v-for="todoItem in todoItems"
25-
v-bind:class="{active: todoItem.isInEditMode}"
26-
v-on:click="switchMode(todoItem)">
25+
v-on:click="activateTodo(todoItem)"
26+
v-bind:class="{active: todoItem.isActive}">
2727
<span >
28-
{{'id="item ${todoItem.id}"'}}
2928
<h3>
29+
{{todoItem.isActive}}
3030
<i class="fa fa-pencil-square-o" aria-hidden="true">
3131
{{todoItem.id}} - {{todoItem.name}}
3232
</i>
@@ -75,34 +75,32 @@ <h3>Add a new todo list</h3>
7575
// item: {title},
7676
todoName: "",
7777
todos: [],
78-
todoItem: {name:""},
78+
todoItem: {name:"", },
7979
todoItems: [],
80-
active: false
80+
active: false,
81+
activeTodo: 1
8182
},
8283
created: function() {
8384
let ajaxUrlLocal = 'http://localhost:3000/api/todos/todos/1/items';
8485
// let ajaxUrlDistant = 'https://test-rails-api.herokuapp.com/api/todos/todos';
8586
var _this = this;
86-
let data = null;
87-
data = $.ajax({
87+
$.ajax({
8888
type: "GET",
8989
url: ajaxUrlLocal,
9090
success: function(data){
91-
_this.todoItems = data;
9291
},
9392
error: function(jqXHR){
9493
console.log("error");
9594
}
9695
})
97-
// .then(function(data) {
98-
99-
// if(data.length) {
100-
// _this.setState({todoItems: data});
101-
// } else {
102-
// _this.setState({todoItems: [data]});
103-
// }
104-
// _this.setState({activeTodo: _this.state.todoItems[0].id});
105-
// });
96+
.then(function(data) {
97+
if(data.length) {
98+
_this.todoItems = data;
99+
} else {
100+
_this.todoItems = [data];
101+
}
102+
_this.todoItems.map(function(item) {item.isActive = false});
103+
});
106104
},
107105
methods: {
108106
addTodo: function() {
@@ -124,6 +122,17 @@ <h3>Add a new todo list</h3>
124122
todoItem.isInEditMode = !todoItem.isInEditMode;
125123
this.todoItems.map(function(item) {if(item.id !== todoItem.id){item.isInEditMode = false}});
126124
},
125+
activateTodo: function(todoItem) {
126+
todoItem.isActive = true;
127+
var index = this.todoItems.indexOf(todoItem);
128+
this.todoItems.splice(index, 1);
129+
this.todoItems.map(function(item) {
130+
item.isActive = false
131+
});
132+
this.todoItems.splice(index, 0, todoItem);
133+
// this.todoItems.push(todoItem).sort();
134+
135+
},
127136
deleteItem: function(todoItem) {
128137
this.todoItems = this.todoItems.filter(function(item) { return item.id !== todoItem.id});
129138
}

0 commit comments

Comments
 (0)