回答編集履歴
2
コメント追加(polyfill)
test
CHANGED
@@ -60,6 +60,8 @@
|
|
60
60
|
|
61
61
|
</template>
|
62
62
|
|
63
|
+
<!-- polyfill -->
|
64
|
+
|
63
65
|
<script src="template.js"></script>
|
64
66
|
|
65
67
|
```
|
1
サンプル追加
test
CHANGED
@@ -13,3 +13,93 @@
|
|
13
13
|
サンプルを提示したいのですが、余裕がないかもしれませんのでここをご覧ください。
|
14
14
|
|
15
15
|
[https://www.html5rocks.com/ja/tutorials/webcomponents/template/](https://www.html5rocks.com/ja/tutorials/webcomponents/template/)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
-- 10/4 追記 サンプル
|
20
|
+
|
21
|
+
```HTML
|
22
|
+
|
23
|
+
<template id="hoge">
|
24
|
+
|
25
|
+
<div>
|
26
|
+
|
27
|
+
<div class="context">
|
28
|
+
|
29
|
+
<a href="http://localhost:3000"></a>
|
30
|
+
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div class="content">
|
34
|
+
|
35
|
+
<div class="item-header">
|
36
|
+
|
37
|
+
<a class="profile"><span class="name">名前</span></a>
|
38
|
+
|
39
|
+
<small class="time">YYYY-MM-DD</small>
|
40
|
+
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div class="text-container">
|
44
|
+
|
45
|
+
<p class="comment">コメント内容</p>
|
46
|
+
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<div class="item-fotter">
|
50
|
+
|
51
|
+
<span class="reply"></span>
|
52
|
+
|
53
|
+
<span class="retweet"></span>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
</div>
|
58
|
+
|
59
|
+
</div>
|
60
|
+
|
61
|
+
</template>
|
62
|
+
|
63
|
+
<script src="template.js"></script>
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```JavaScript
|
70
|
+
|
71
|
+
document.addEventListener('DOMContentLoaded', function(event) {
|
72
|
+
|
73
|
+
var data = [["URLA","名前A","日付A","コメントA"],["URLB","名前B","日付B","コメントB"],["URLC","名前C","日付C","コメントC"]];
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
var fragment = document.createDocumentFragment();
|
78
|
+
|
79
|
+
var content = document.getElementById('hoge').content;
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
for (var i = 0, len = data.length; i < len; i++) {
|
84
|
+
|
85
|
+
var clone = content.cloneNode(true);
|
86
|
+
|
87
|
+
clone.querySelector('.context a').href = data[i][0];
|
88
|
+
|
89
|
+
clone.querySelector('.name').textContent = data[i][1];
|
90
|
+
|
91
|
+
clone.querySelector('.time').textContent = data[i][2];
|
92
|
+
|
93
|
+
clone.querySelector('.comment').textContent = data[i][3];
|
94
|
+
|
95
|
+
fragment.appendChild(clone);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
document.body.appendChild(fragment);
|
102
|
+
|
103
|
+
});
|
104
|
+
|
105
|
+
```
|