diff --git a/js/sub4.js b/js/sub4.js new file mode 100644 index 0000000..132ed67 --- /dev/null +++ b/js/sub4.js @@ -0,0 +1,36 @@ +$.getJSON("restAPI/phone.php", data => { + if(data.statusCd !== "200") { + alert(data.statusMsg); + + return location.href = "/"; + }; + + const items = [...data.items].reduce(((item, { sn, deptNm, name, telNo }) => { + item[deptNm] = [...item[deptNm] ?? [], {sn, name, telNo}]; + + return item; + }), {}); + + Object.keys(items).forEach(tab => { + $("#tab-box").append(`
  • ${tab}
  • `); + + $("#phone-box").append(` +
    +
    +

    ${tab}

    +
    +
    +
    + ${items[tab].map(item => `
  • ${item["name"]}
  • ${item["telNo"]}
  • `)} +
    +
    + `); + }); + + $(document).on("click", ".tab", function() { + $(this).addClass("active-tab").siblings().removeClass("active-tab"); + + $(this).text() === "전체" ? $(".phone-box").css({"display": "flex"}) : $(".phone-box").hide(); + $(`.phone-box[data-tab=${$(this).text()}`).css({"display": "flex"}); + }); +}); \ No newline at end of file