test.html
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<style>
div{
font-size: .9em;
color: #4a4a4a;
}
a{
text-decoration-line: none;
color: #4a4a4a;
}
</style>
<script>
$(document).ready(function(){
$.getJSON('water.json', function(data){
var html = [];
$.each(data, function(i, item){
console.log(item.product.length);
html.push('<div class="container">')
var cnt = 0;
var name = "";
for(var num = 0; num < item.product.length; num++){
if(name != item.product[num].name){
if(num!=0){html.push('</div>')} // close col
if(num!=0){if(cnt%3==0){html.push('</div>');}} // close row
if(cnt%3==0){html.push('<div class="row">');} // open row
cnt = cnt + 1;
html.push('<div class="col-sm">');
html.push('<div><img src="'+item.product[num].img+'" target="_blank" width="200" height="200"></div>');
html.push('<div> 상품명 : '+item.product[num].name+'</div>');
html.push('<div> mart : '+item.product[num].mart+'</div>');
html.push('<div> 가격(100ml당가격) : '+item.product[num].price+'('+item.product[num].unit+')'+'</div>');
}
else{
html.push('<div> mart : '+item.product[num].mart+'</div>');
html.push('<div> 가격(100ml당가격) : '+item.product[num].price+'('+item.product[num].unit+')'+'</div>');
}
name = item.product[num].name;
}
html.push('</div>'); // close col
html.push('</div>'); // close row
html.push('</div>'); // close container
});
$('#data-container').html(html.join(''));
});
});
</script>
</head>
<body>
<h2>얄리얄리얄라셩</h2>
<div id="data-container"></div>
</body>
</html>