回答編集履歴
2
微修正
test
CHANGED
@@ -32,6 +32,12 @@
|
|
32
32
|
|
33
33
|
}
|
34
34
|
|
35
|
+
|
36
|
+
|
37
|
+
//略
|
38
|
+
|
39
|
+
|
40
|
+
|
35
41
|
const createDeleteButton = (tableRecord) => {
|
36
42
|
|
37
43
|
var index = tableRecord.rowIndex-1;
|
1
実装について追記します
test
CHANGED
@@ -11,3 +11,45 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
`tableRecord`は<tr>要素であり数値じゃないので直接spliceに入れようとすると0になってしまうのだと思います(おそらく)
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
-----
|
18
|
+
|
19
|
+
実装を追記します。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```js
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
const showTodos = () => {
|
28
|
+
|
29
|
+
//略
|
30
|
+
|
31
|
+
tableAction.appendChild(createDeleteButton(tableRecord));
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
const createDeleteButton = (tableRecord) => {
|
36
|
+
|
37
|
+
var index = tableRecord.rowIndex-1;
|
38
|
+
|
39
|
+
const deleteButton = document.createElement('button');
|
40
|
+
|
41
|
+
deleteButton.textContent = '削除';
|
42
|
+
|
43
|
+
deleteButton.addEventListener('click', () => {
|
44
|
+
|
45
|
+
todos.splice(index, 1);
|
46
|
+
|
47
|
+
showTodos();
|
48
|
+
|
49
|
+
});
|
50
|
+
|
51
|
+
return deleteButton;
|
52
|
+
|
53
|
+
};
|
54
|
+
|
55
|
+
```
|