Any solution for a slow dropdown?

Hello,
I’m a new Wix user and I tried to code a dropdown that filters some elements of my dataset.
It doesn’t seem so efficient, though. Could someone suggest me any tip in order to speed up the loading?
I’ll attach a demo video and code.

import wixData from 'wix-data';

$w.onReady(function () {
 
    $w("#dataset1").onReady( () => {
 //Because when the page is loaded, I want the "mondoscuola" elements already shown
        $w("#dataset1").setFilter(wixData.filter().eq("mondoscuola", true));

 //I iterate to collapse all the repeated boxes
        $w('#repeater1').onItemReady(() => { 
        $w('#repeater1').forEachItem(($item, data, i) => { 
            $item('#box1').collapse();
        });
    });

    });
});

export function arrowOpen_click(event) {
$w('#repeater1').forEachItem(($i, data, i) => {
 if( $i("#arrowClose").isVisible ) {
        $i("#arrowClose").hide();
        $i("#arrowOpen").show();
        $i('#box1').collapse();
    }
        });

let $item = $w.at(event.context);
     $item("#arrowOpen").hide();
     $item("#arrowClose").show();
     $item("#box1").expand();
}

export function arrowClose_click(event) {
 let $item = $w.at(event.context);
     $item("#arrowClose").hide();
     $item("#arrowOpen").show();
     $item("#box1").collapse();
}

export function dropdown1_change(event) {
 let filterType = $w("#dropdown1").value;

 if (filterType === "mondoscuola") {
            $w("#dataset1").setFilter(wixData.filter().eq("mondoscuola", true));
        }
 if (filterType === "cdc") {
            $w("#dataset1").setFilter(wixData.filter().eq("cdc", true));
        }
 if (filterType === "postlaurea") {
            $w("#dataset1").setFilter(wixData.filter().eq("postlaurea", true));
        }
 
}

It seems that there is no major problem with your program. Have you published your program, after publish the speed is about five times faster than privew.

You have a forEachItem function inside of the onItemReady function which is incorrect. You should only need one or the other. I would suggest referring to the docs for details on the proper use of each function.

Yes, you can only choose one of forEachItem() and onItemReay().

Thanks a lot! Indeed, after publishing the site, it loaded immediately and even without modifying the code.

Thank you so much! In fact, it was useless the forEachItem function for my purposes. Thanks again :smiley: