Need help: Repeater-dataset

On the page there is a repeater with one template connected to the database “# dataset1”, which allows you to display the entire collection. Next, I would like to click on the image and show more detailed information on the selected element of the database. In one of the fields in the database “# dataset1” I wrote down the sequence numbers of the elements of the database, and the text of the repeater pattern “# text1” was connected to this field. In processing the image click, I wrote this script
let n = Number.parseInt ($ w (“# text1”). text);
console.log (n);
$ w (“# dataset1”). setCurrentItemIndex (n);
console.log ($ w (“# dataset1”). getCurrentItemIndex ());
But in spite of the fact that “n” is always transmitted correctly, $ w (“# dataset1”). setCurrentItemIndex (n); always returns “0”. The database always starts with the first element. What am I doing wrong? Tell me please

Answer is promises.

This operation is asynchronic. Meaning that both setCurrent… and getCurrent… are executed IN PARALLEL.
For you that means that when you try to read this index, it’s not yet set to any number, it’s default - and that is why it’s “0”

It should work with this:

let n = Number.parseInt($w("#text1").text); 
console.log (n);     

Hi, Mikhail

Many thanks, but it did not help. When I connected the error handling, I received a message:

DatasetError: The “setCurrentItemIndex” function cannot be called on the dataset because the dataset was selected using a repeated item scope selector. Read more about repeated item scope selectors:$w.Repeater.html#repeated-item-scope

Do not tell me the next steps? I’m just starting to program in codes.

I believe problem is because you re trying to set index inside a repeater’s container scope… It doesn’t have sense in this context

anyway, i need context to help you with this

Please, share a link toyour site where you expirience problems and try to describe what you want to achieve

On the page strip there is a repeater connected to the collection of clothes “BOP” including 18 images for each element of the collection. Now there are 10 elements in the collection, but expansion is expected. The repeater gives the basic data for the collection. To display detailed information on a collection item on another strip, a viewer is placed, and a questionnaire in the form of a drop-down list for items of clothing. Upon completion of information input, an order with a calculated price that can be sent by mail. The viewer consists of one detailed image and 3 icons specifying a further output front, side, back on detailed image. Manage the movement of the collection can be using the buttons, linked by reference to the “next” and “previous.”
What I want to achieve.
When the page is called, the repeater displays the main elements of the collection. The viewer is hidden first. By clicking on one of the repeater images, the viewer is shown with the selected collection item. Now this does not happen. Base “BOP” begins with the first element of the collection.

Mikhail, I express my gratitude for your readiness to help me.


I am unable to run your site in Preview - it locks up no matter what page I try to run from.

However, your problem with access to the dataset is that the $w context selector of the onClick() function refers to the repeater item and does not have access to the page context. Therefore $w does not “see” the page’s dataset.

You need to change the context selector of your onClick() function, sort of like this:

export function button36_click(event, $somethingelse) {
    let n = Number($somethingelse("#text155").text);
        .then(function () {
    $somethingelse("#text160").text = "front";
    $somethingelse("#image36").src = $somethingelse("#image15").src;
    $somethingelse("#columnStrip12").scrollTo(0, 300);

As you can see, I changed the context selector to $somethingelse, and then I access the dataset with the $w global context selector: $w(#dataset1").

Another way would be to define the onClick() function in the onItemReady() function. You can see how that’s done in the onItemReady() API.

Good luck,


1 Like

Thank you! Now it is clear.

1 Like

Glad to hear it worked out.