从给定的原型获取json结果

时间:2018-10-24 09:30:16

标签: javascript node.js

我有一些原型,下面在 prototype部分中给出,我想获得我在 resulted-output 部分中指定的结果。要使用某些es-6高阶功能来获取结果,请帮助获取我在r 结果输出部分

中描述的结果

感谢前进

**prototype:**
let data = [
    {
        "rooms_id": 27,
        "room_num": 101,
        "catetory" : "king",
        "booking_id": 248,
        "checkin_date": "2018-10-23 10:30:00",
        "checkout_date": "2018-10-24 10:30:00",
        "booking_status": "booked"
    },
    {
        "rooms_id": 27,
        "room_num": 101,
        "catetory" : "king",
        "booking_id": 249,
        "checkin_date": "2018-10-24 11:30:00",
        "checkout_date": "2018-10-25 11:30:00",
        "booking_status": "booked"
    },
    {
        "rooms_id": 30,
        "room_num": 102,
        "catetory" : "king",
        "booking_id": 260,
        "checkin_date": "2018-10-23 11:30:00",
        "checkout_date": "2018-10-25 11:30:00",
        "booking_status": "booked"
    },

    {
        "rooms_id": 31,
        "room_num": 102,
        "catetory" : "queen",
        "booking_id": 245,
        "checkin_date": "2018-10-22 12:30:00",
        "checkout_date": "2018-10-23 12:30:00",
        "booking_status": "vacant"
    },
    {
        "rooms_id": 31,
        "room_num": 102,
        "catetory" : "queen",
        "booking_id": 246,
        "checkin_date": "2018-10-23 12:30:00",
        "checkout_date": "2018-10-24 12:30:00",
        "booking_status": "booked"
    },
 ]



**resulted output:**
{
    "king" : {
        "101" : {
            "2018-10-23 10:30:00" : {
                "rooms_id": 27,
                "room_num": 101,
                "catetory" : "king",
                "booking_id": 248,
                "checkin_date": "2018-10-23 10:30:00",
                "checkout_date": "2018-10-24 10:30:00",
                "booking_status": "booked"
            },
            "2018-10-24 11:30:00" : {
                "rooms_id": 27,
                "room_num": 101,
                "catetory" : "king",
                "booking_id": 249,
                "checkin_date": "2018-10-24 11:30:00",
                "checkout_date": "2018-10-25 11:30:00",
                "booking_status": "booked"
            },
        },
        "102" : {
            "2018-10-23 10:30:00" : {
                "rooms_id": 30,
                "room_num": 102,
                "catetory" : "king",
                "booking_id": 250,
                "checkin_date": "2018-10-23 10:30:00",
                "checkout_date": "2018-10-25 10:30:00",
                "booking_status": "booked"
            }
        }
    },
    "queen" : {
        "101" : {
            "2018-10-22 10:30:00" : {
                "rooms_id": 31,
                "room_num": 105,
                "catetory" : "queen",
                "booking_id": 251,
                "checkin_date": "2018-10-22 10:30:00",
                "checkout_date": "2018-10-23 11:30:00",
                "booking_status": "booked"
            },
            "2018-10-24 11:30:00" : {
                "rooms_id": 31,
                "room_num": 105,
                "catetory" : "queen",
                "booking_id": 252,
                "checkin_date": "2018-10-23 11:30:00",
                "checkout_date": "2018-10-24 12:30:00",
                "booking_status": "booked"
            },
        },

    },
} 

1 个答案:

答案 0 :(得分:0)

使用models,您可以这样做

lodash/setWith

欢迎堆栈溢出。请记住,这不是代码编写服务,在以后的问题中,您应该发布自己的解决方案尝试。通过这种方式,我们可以更好地帮助您了解问题出在哪儿,这不仅是让别人为您编写代码的一种更好的学习方法。