"id": 1,
"property_type": "Квартира",
"queue": null,
"building": 1,
"section": 1,
"floor": 2,
"number": 1,
"status": "statusFree",
"type": 98.0,
"rooms": 3,
"levels": 2,
"square_total": 98.0,
"price": 651700000
}, {
"id": 2,
"property_type": "Квартира",
"queue": null,
"building": 1,
"section": 1,
"floor": 2,
"number": 2,
"status": "statusReserv",
"type": 56.0,
"rooms": 2,
"levels": 2,
"square_total": 56.0,
"price": 372400000
}, {
"id": "3",
"property_type": "Квартира",
"queue": null,
"building": 1,
"section": 1,
"floor": 2,
"number": 3,
"status": "statusSold",
"type": 107.0,
"rooms": 3,
"levels": 2,
"square_total": 107.0,
"price": 711550000
}]
}
var status = {};
status['statusFree'] = "Свободно";
status['statusReserv'] = "Забронировно";
status['statusSold'] = "Продано";
как сделать так чтобы в json данных можно было выводить переменные из обьекта ?
var obj = { "building": [{ "id": 1, "property_type": "Квартира", "queue": null, "building": 1, "section": 1, "floor": 2, "number": 1, "status": "statusFree", "type": 98.0, "rooms": 3, "levels": 2, "square_total": 98.0, "price": 651700000 }, { "id": 2, "property_type": "Квартира", "queue": null, "building": 1, "section": 1, "floor": 2, "number": 2, "status": "statusReserv", "type": 56.0, "rooms": 2, "levels": 2, "square_total": 56.0, "price": 372400000 }, { "id": "3", "property_type": "Квартира", "queue": null, "building": 1, "section": 1, "floor": 2, "number": 3, "status": "statusSold", "type": 107.0, "rooms": 3, "levels": 2, "square_total": 107.0, "price": 711550000 }] }; var statusMap = {}; statusMap['statusFree'] = "Свободно"; statusMap['statusReserv'] = "Забронировно"; statusMap['statusSold'] = "Продано"; function objStatusToText(obj, statusMap) { obj = {...obj}; obj.building = obj.building.map(v => { v = {...v}; v.status = statusMap[v.status]; return v; }); return obj; } objStatusToText(obj, statusMap);
Обсуждают сегодня