@minarirafael
Aas i can see → it is also not wrong → because NO ERRORS are in your CONSOLE.
Now what to do? → open the 3-dots → this will give you an insight into the presented OBJECT with all it’s given RESULTS.

What was your plan, one more time?
Can’t get the selected item of a dataset and export to a lightbox
In the dynamic page I get a random photo of a dataset and show it.
When the user clicks on the photo it should open a lightbox with more information about the clicked item.
Ok first make clear thoughts about your SETUP and what you want to achieve.
Your SETUP:
-You have a DYNAMIC-PAGE connected trough a DATASET.
-On your DYNAMIC-PAGE you have different elements and one of these elements is a clickable-pic, where you want to set a triggered-function which will open a light box.
-When Lightbox is opened → you want to show all DATA which belongs to the selected pic, right?
So what are your steps?
-
Get the current selected ITEM on your dynamic page (you surely know, that on dynamic pages always just ONE-ITEM can be shown at once.
-
Generating an OBJECT with all the needed DATA, what you want to send to your LIGHTBOX when opening it (using the contect of the LIGHTBOX).
-
Showing RESULTS inside your LIGHTBOX, either using a REPEATER or by placed elements (like dropdowns, inputs, textfields and so on…) on your LIGHTBOX.
So → let’s GO!
STEP-1: Getting the neccessayry data for the LIGHTBOX (using getCurrentItem)
https://www.wix.com/velo/reference/wix-dataset/dataset/getcurrentitem
https://www.wix.com/velo/reference/wix-dataset/dataset/gettotalcount
Now you have your TOTAL-ITEMS-COUNT and the first basic part of your code → you have the DATA of the current selected ITEM. Do not forget → on DYNAMIC-PAGES you will always get just one ITEM-DATA, to be more precise → always the current selected one (getCurrentItem)!
Your CODE after STEP-1:
var DATASET = "#dataset1"
$w.onReady( () => {
$w(DATASET).onReady( () => {
let myItem = $w(DATASET).getCurrentItem(); console.log("ITEM: ", myItem);
let count = $w("#myDataset").getTotalCount();
});
});
But hey —> What the hell! → You wanted a RANDOM PIC → RANDOM selected ITEM! So let’s generate a RANDOM one! We will use your already generated codes.
let rnd=Math.floor(Math.random()*count); console.log("My random-number is = ", rnd);
STEP-2: Random-ITEM
What happened in the code now? YES! → Now the order is different and we do not use → getCurrentItem anymore, because we want to get a random item!
Why the ORDER of COMMANDS changed? → Because you first have to know the TOTAL-COUNT of your ITEMS to generate your RANDOM-DIGIT.
After you have generated your random DIGIT → you can search for that ITEM in your DATASET/DATABASE of the gotten RANDOM DIGIT-RESULT.
This time we use → getItems()… WHY? → because we need a RANDOM one!
var DATASET = "#dataset1"
$w.onReady( () => {
$w(DATASET).onReady( () => {
let count = $w("#myDataset").getTotalCount(); console.log("Total-Items: ", count);
let rnd = Math.floor(Math.random()*count); console.log("RANDOM-NUMBER: ", rnd);
let myItem = $w(DATASET).getItems(rnd,1); console.log("ITEM: ", myItem);
});
});
HURAYYYYY! Second STEP done! → You have your RANDOM-selected item.
Now try to figure out the same logical way → how to get that found RANDOM-ITEM-DATA → into your LIGHTBOX.
As you can see → your very first approach to generate a random pic, could not work → because you have had any connection between PIC and random gotten DATA. → Never mix DATASETS with wix-DATA → this will just cause you a lot of headaches!!!
Go either the wix-data-way, or use the dataset-one, but try not to mix them.
STEP-3: Preparing DATA to be send to LIGHTBOX (generating an OBJECT)
…
…
…
…
…
STEP-4: Open Lightbox with with generated DATA…
import wixWindow from 'wix-window';
6
7export function openButton_click(event) {
8 wixWindow.openLightbox("MyLightBox", {
9 "pageSend1": $w('#pageSend1').value,
10 "pageSend2": $w('#pageSend2').value
11 })
12 .then( (data) => {
13 $w('#pageReceive1').text = data.lightBoxSend1;
14 $w('#pageReceive2').text = data.lightBoxSend2;
15 } );
16}
https://www.wix.com/velo/reference/wix-window/lightbox-obj/getcontext
…and so on…
And do not forget to use —> CONSOLE-LOGS!
CONSOLE → is your BEST-FRIEND !
EDIT: By the way → perhaps you can even skip → STEP-3, because you have already an RESULT-OBJECT. Just send the whole OBJECT to your LIGHTBOX.
You can then decide directly on your LIGHTBOX, which data you want to use out of the whole OBJECT!