When i click select box, client shows the specific items.

e.g) food → food goods, drink → drink goods.

views/index.ejs

$(document).ready(function () {
    get_goods()
    $("#categorySelect").on("change", function () {
        get_goods($(this).val())
    })
})

: When window opens, call function get_goods without any argument. And Whenever client changes selectbox value, it calls function get_goods again with changed value.

function get_goods(category) {
    $("#goodsList").empty()

    $.ajax({
        type: "GET",
        url: `/api/goods${category ? "?category=" + category : ""}`,
        data: {},
        success: function (response) {
            let goods = response['goods'];
            console.log(goods);

            for (let i = 0; i < goods.length; i++) {
                make_card(goods[i])
            }
        }
    });
}

: When function get_goods is called, make list empty. and call goods api to show. if there is argument(category), it's gonna be "/api/goods?category=food" or "/api/goods?category=drink", and if there is no argument, it's gonna be just "/api/goods".

/api/goods

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/542be54b-dd9c-4385-b8b0-705dd3fe8735/Screen_Shot_2021-06-26_at_9.51.38_AM.png

/api/goods?category=food

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/415ca0cd-f513-469d-bf4b-b63976d916ba/Screen_Shot_2021-06-26_at_9.39.24_AM.png

api/goods?category=drink

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/826dd352-670d-40b0-ba40-ef9e5ce7360c/Screen_Shot_2021-06-26_at_9.39.50_AM.png