import wixLocation from 'wix-location';
import wixData from 'wix-data';
let documents;
$w.onReady(function () {
//getting all documents from the collection
wixData.query("documents")
.find()
.then((results) => {
//setting the results to the variable declared above
documents = results.items; //see item below
})
.catch((err) => {
let errorMsg = err;
});
});
export function dropdown1_change(event, $w) {
let selectedOption = $w('#dropdown1').value;
switch (selectedOption) {
//these options are the values that were set to the dropdown
case 'firstItem':
wixLocation.to(documents[0].doc);
break;
case 'secondItem':
wixLocation.to(documents[1].doc);
break;
case 'thirdItem':
wixLocation.to(documents[2].doc);
break;
}
}
Any comments or suggestions? I don’t know much Javascript and it’s starting to feel like I’m going to have to learn Javascript just to add a stupid dropdown with a download link.
The code from Tal, wouldn’t connect the Titles from the Dataset to the dropdown options for me, the below code at least linked that.
I still get the same error about the documents selection not existing - Is there something in my code which does not link to the document column of my dataset?
import wixLocation from ‘wix-location’ ; import wixData from ‘wix-data’ ; let documents ;
$w . onReady ( function () {
//getting all documents from the collection
wixData . query ( “documents” )
. find ()
. then (( results ) => {
//setting the results to the variable declared above
documents = results . items ; //see item below
})
. catch (( err ) => { let errorMsg = err ;
});
});
export function dropdown1_change ( event , $w ) { let selectedOption = $w ( ‘#dropdown1’ ). value ;
switch ( selectedOption ) {
//these options are the values that were set to the dropdown case ‘ENGLISH US’ :
wixLocation . to ( File [ 1 ]. doc ); break ; case ‘ENGLISH UK’ :
wixLocation . to ( File [ 2 ]. doc ); break ; case ‘Sample’ :
wixLocation . to ( File [ 3 ]. doc ); break ;
}
}
The error says "the “documents” collection doesn’t exists.
This means you haven’t named your collections “documents” but something else.
In the code :
wixData.query("documents")
“documents” must be replaced by your collection name, which is “downloadFile”
Try :
import wixLocation from 'wix-location';
import wixData from 'wix-data';
let documents;
$w.onReady(function () {
//getting all documents from the collection
wixData.query("downloadFile")
.find()
.then((results) => {
//setting the results to the variable declared above
documents = results.items; //see item below
})
.catch((err) => {
let errorMsg = err;
});
});
export function dropdown1_change(event, $w) {
let selectedOption = $w('#dropdown1').value;
switch (selectedOption) {
//these options are the values that were set to the dropdown
case 'ENGLISH US':
wixLocation.to(File[1].doc);
break;
case 'ENGLISH UK':
wixLocation.to(File[2].doc);
break;
case 'Sample':
wixLocation.to(File[3].doc);
break;
}
}