Hey everybody!
I am also quite new to the platform and also to JavaScript. I have a similar problem like emmaparkerfilmmaker, but unfortunately the solution, which was provided does not work for me.
Here is my problem:
I have a database (DataSet) with different Hotels. Each Hotel has a name (HName), different seasons, different Meal Categories, which can be selected, different rooms etc. In the end I want to filter my DataSet according to the Hotel Name, which was selected in a Dropdown (dropdown is linked to the database to display all available hotel names independent of filter). After having filtered only this Hotel, I want to search for the desired price (according to the season, selected meal and selected room type).
Here is my code:
export function DropH1Name_change(event) {
H1Name = $w(‘#DropH1Name’).value;
console.log('Name of Hotel 1: ’ + H1Name);
}
function searchHotelPrice (DataSet, HName, HMeal, HRoom, date) {
DataSet.setFilter(wixData.filter()
.contains(“name”, HName));
console.log(DataSet.getCurrentItem().name)
let price = 0;
if (date >= DataSet.getCurrentItem().s1_begin && date <= DataSet.getCurrentItem().s1_end){
switch (HMeal) {
case "BB":
switch (HRoom) {
case "Single": price = DataSet.getCurrentItem().s1BbSingle; break;
case "Double": price = DataSet.getCurrentItem().s1BbDouble; break;
case "Triple": price = DataSet.getCurrentItem().s1BbTriple; break;
case "Quadruple": price = DataSet.getCurrentItem().s1BbQuadruple; break;
default: break;}
break;
case "HB":
switch (HRoom) {
case "Single": price = DataSet.getCurrentItem().s1HbSingle; break;
case "Double": price = DataSet.getCurrentItem().s1HbDouble; break;
case "Triple": price = DataSet.getCurrentItem().s1HbTriple; break;
case "Quadruple": price = DataSet.getCurrentItem().s1HbQuadruple; break;
default: break;}
break;
case "FB":
switch (HRoom) {
case "Single": price = DataSet.getCurrentItem().s1FbSingle; break;
case "Double": price = DataSet.getCurrentItem().s1FbDouble; break;
case "Triple": price = DataSet.getCurrentItem().s1FbTriple; break;
case "Quadruple": price = DataSet.getCurrentItem().s1FbQuadruple; break;
default: break;}
break;
case "AIC":
switch (HRoom) {
case "Single": price = DataSet.getCurrentItem().s1AicSingle; break;
case "Double": price = DataSet.getCurrentItem().s1AicDouble; break;
case "Triple": price = DataSet.getCurrentItem().s1AicTriple; break;
case "Quadruple": price = DataSet.getCurrentItem().s1AicQuadruple; break;
default: break;}
break;
default: break;
}
} else if { //much more code, basically the same as above only for other seasons
} else if { price =0;
}
return price;
}
export function button1_click(event) {
let date = $w(‘#DatePickArrival’).value;
let cost = 0;
TotHotel1Cost = 0;
for (var i = 0; i < ArrHotel1Rooms.length; i++) {
cost = searchHotelPrice($w(‘#DataHotel’), H1Name, H1Meal, ArrHotel1Rooms[i], date);
TotHotel1Cost += cost;
}
$w(‘#text15’).text = String(TotHotel1Cost);
}
The problem is not getting the value out of a hotel, but first of all to find the hotel. Every time I click the button it gives me the correct cost, but all the time for the same hotel, independent of what H1Name is.
For example: H1Name is “Blue Sapphire Hotel” in Season 1, H1Meal=“FB”, Room Category = “Double” (stored in Array ArrHotel1Rooms). I now, ALWAYS get the cost for e.g. “World Wonders Hotel”, in the correct season 1, with correct meals (full board), room category (double) and therefore price.
What did I do wrong? I think it has something to do with DataSet.getCurrentItem(), because I thought that´s the way how to apply the filter. Is there any way how to set the Current Item?
Any help would be greatly appreciated!! Thanks a lot!