I have a filter that is imported from backend code as part of my maps HTML. I’m wanting to use page data to use as part of the filter (e.g. customer selects min price / max price etc.).
How would I go about sending this page data to my backend code?
import {backendFunction} from 'backend/file';
export function somethingHappens(event) {
let data = $w("#whateverDataYouWantToSend").value;
backendFunction(data)
.then( (responseFromBackend) => {
//perform something here
});
}
I’m looking to link your code ( code block 1 ) to use to send page data to use in my backend code ( code block 2 ).
My page code (the one you have sent) works on_click on a button which takes data from a couple of dropdowns to use as part of a filter in my backend code.
Front end code (yours- ish ):
export function sendData_button(event) {
let data = $w("#minPrice").value; // the min price dropdown on the customer search maps page (this page)
let data2 = $w("#maxPrice").value; // the max price dropdown on the customer search maps page (this page)
getLocations(data);
getLocations(data2);
}
My backend code:
export function getLocations() {
let smallPrice = data - 1; // the min price from the customer search maps page
let bigPrice = data2 + 1; // the max price from the customer search maps page
return wixData.query("properties")
.between("price", smallPrice, bigPrice)
.find()
.then((results) => {
return results.items; // items is an array of locations from the collection
})
.catch((err) => {
let errorMsg = err;
});
}
But I’m not sure how to get the two to talk to each other! I’ve got pretty far with it all linking the HTML to maps using another walk through on another thread and this is the final hurdle!
export function sendData_button(event) {
let data = $w("#minPrice").value; // the min price dropdown on the customer search maps page (this page)
let data2 = $w("#maxPrice").value; // the max price dropdown on the customer search maps page (this page)
getLocations(data, data2);
}
Then you are returning the results from the backend but you are not receiving it on the page. To receive the results from the backend do this:
export function sendData_button(event) {
let data = $w("#minPrice").value; // the min price dropdown on the customer search maps page (this page)
let data2 = $w("#maxPrice").value; // the max price dropdown on the customer search maps page (this page)
getLocations(data, data2)
.then( (results) => {
//do something with the results
});
}