test.html 2.34 KB
<!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>