1
I have the following json object:
var json = {
"tpAmbiente":null,
"hotelPesquisa":[
{
"dtEntrada":"20170510",
"dtSaida":"20170511",
"hotel":{
"id":94,
"nome":"Itamarati"
},
"quarto":[
{
"quartoUh":[
{
"nQUarto": 1,
"tarifa":{
"vlDiariaTotal":157.21,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
{
"nQUarto": 2,
"tarifa":{
"vlDiariaTotal":157.21,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
]
}
]
},
{
"dtEntrada":"20170510",
"dtSaida":"20170511",
"hotel":{
"id":95,
"nome":"copacabana"
},
"quarto":[
{
"quartoUh":[
{
"nQUarto": 1,
"tarifa":{
"vlDiariaTotal":102.1,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
{
"nQUarto": 2,
"tarifa":{
"vlDiariaTotal":102.1,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
]
}
]
},
{
"dtEntrada":"20170510",
"dtSaida":"20170511",
"hotel":{
"id":96,
"nome":"Itamarati"
},
"quarto":[
{
"quartoUh":[
{
"nQUarto": 1,
"tarifa":{
"vlDiariaTotal":157.21,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
{
"nQUarto": 2,
"tarifa":{
"vlDiariaTotal":157.21,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
]
}
]
},
{
"dtEntrada":"20170510",
"dtSaida":"20170511",
"hotel":{
"id":96,
"nome":"Litoral Hotel"
},
"quarto":[
{
"quartoUh":[
{
"nQUarto": 1,
"tarifa":{
"vlDiariaTotal":1001.00,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
{
"nQUarto": 2,
"tarifa":{
"vlDiariaTotal":1001.00,
"desconto":null
},
"qtDisponivel":null,
"desconto":null
},
]
}
]
}
]
};
How do I filter this object so that only show hotels where the price is higher than 100 and lower than 900?
The price stays on:
hotelPesquisa[].quarto[].quartoUh[].tarifa.vlDiariaTotal
Return I need:
"hotelPesquisa":[ { "dtEntrada":"20170510", "dtSaida":"20170511", "hotel":{ "id":94, "nome":"Itamarati" }, "quarto":[ { "quartoUh":[ { "nQUarto": 1, "tarifa":{ "vlDiariaTotal":890.21, "desconto":null }, "qtDisponivel":null, "desconto":null }, { "nQUarto": 2, "tarifa":{ "vlDiariaTotal":890.21, "desconto":null }, "qtDisponivel":null, "desconto":null }, ] } ] }, { "dtEntrada":"20170510", "dtSaida":"20170511", "hotel":{ "id":95, "nome":"copacabana" }, "quarto":[ { "quartoUh":[ { "nQUarto": 1, "tarifa":{ "vlDiariaTotal":102.1, "desconto":null }, "qtDisponivel":null, "desconto":null }, { "nQUarto": 2, "tarifa":{ "vlDiariaTotal":102.1, "desconto":null }, "qtDisponivel":null, "desconto":null }, ] } ] }, { "dtEntrada":"20170510", "dtSaida":"20170511", "hotel":{ "id":96, "nome":"Itamarati" }, "quarto":[ { "quartoUh":[ { "nQUarto": 1, "tarifa":{ "vlDiariaTotal":890.21, "desconto":null }, "qtDisponivel":null, "desconto":null }, { "nQUarto": 2, "tarifa":{ "vlDiariaTotal":890.21, "desconto":null }, "qtDisponivel":null, "desconto":null }, ] } ] } ]
Is there any way I can filter the object with jQuery and maintain all properties? Thank you!
You want to remove the rooms that are out of price or keep the rooms but remove the hotel where none of the rooms is within price?
– Sergio
Is it possible to do both? But I think it is better to remove the hotel
– usuario
It’s possible to take hotels and rooms, that’s what you’re looking for?
– Sergio
That’s right. In some cases I need to take away the hotels and there are other cases I need to take away the rooms
– usuario