Hello! I would like to put a function to be able to select an item from two dropdowns, then filter data collection and show the number of filtered items as a text. Who knows what is wrong in my code?
export function searchjobs_click(event) { $w("#text45").expand(); $w("#button13").expand(); $w("#button13").enable(); } export function dataset1_ready() { // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4 // Add your code for this event here: let query = wixData.query("dataset1"); wixData.query("dataset1") .eq("title", "location") .gt($w('dropdown1).value, $w('dropdown2).value) .count() .then( (num) => { let numberOfItems = num; $w('#text45').text = "There are "+ num + " " + " open job postings"; } ) .catch( (error) => { let errorMsg = error.message; let code = error.code; } ); } function query(Postedjobs number): wix_data
так что у нас тут за проблемка?
Oh, i think we have here a little problem 😁.
And it's --> like always <-- the same problem.
You are mixing between Wix-Data and DATASET! Don't worry, this is almost already a standard issue, almost every unexperienced user do this mistake.
If you want to know the answer to your question...
Who knows what is wrong in my code? --> Do you really want to know that? 😁
Then i would say --> almost everything is wrong in your code 😁 😁 😁
Well, you have now two options and you also will have to make a descision.
1) You either go the Wix-Data-Way using queries.
2) Or you go the DATASET-Way using a dataset.
Are you already using a --> DATASET?
If so, then continue the --> DATASET-WAY.
Here you can see a little prepared CODE-SKELETTON, which could help you out.
Modify the following to get this code working....
-modify/adjust --> all element-IDs (code and element-IDs should be identical)
-add a reset-button , with ID --> "btnReset", onto your page
Your code then should look like something like....
import wixData from 'wix-data'; var myFilter = []; var DATASET = "#dataset1"; $w.onReady(()=> { $w(DATASET).onReady(()=> { $w('#dropdown1, #dropdown2').onChange(()=>{SEARCH_ENGINE();}); $w('#btnReset').onClick(()=>{RESET();}); $w("#searchjobs").onClick(()=> {SEARCH_ENGINE(); $w("#text45").expand(); $w("#button13").expand(); $w("#button13").enable(); }); }); }); function SEARCH_ENGINE() {console.log("Search-Engine started"); let filter = wixData.filter(); filter = filter.eq("title", "location"); if ($w('#dropdown1').value && $w('#dropdown2').value) { filter = filter.gt($w('#dropdown1').value, $w('#dropdown2').value); } $w(DATASET).setFilter(filter) .then(()=>{console.log(myFilter); let count = $w(DATASET).getTotalCount().toString(); console.log("Total-Count = " + count); $w('#text45').text= "There are "+count+ " " + " open job postings"; }); } function RESET () { $w("#dropdown1").selectedIndex = undefined; $w("#dropdown2").selectedIndex = undefined; myFilter = []; }
Modify and complete the code to your own needs, good luck!