Hi everyone,
I am relatively new to coding with Velo and appreciate your assistance. I am struggling with populating a Repeater when the Collection changes.
I have a master list of Companies in one repeater that displays information on rows subject to filters. I have included a checkbox in each row in the master Repeater so that the user can select Companies of interest. I then load the selected companies into a Collection (I call tmpDbSelect for now).
I created another repeater that I called rptSelectedCompanies that should display only the companies selected by the user. This repeater is linked to the tmpDbSelect collection.
When the user checks or unchecks a checkbox, the tmpDbSelect correctly reflects the selected companies. However, the repeater rptSelectedCompanies seems to update the information erratically. Sometimes it ignores some a record though I can see it in the Content Manager table,
My reading of the forum so far has pointed me to the fact that the repeater rptSelectedCompanies is updating before the collection finishes its update. There were some suggestions of using async/await as a way to govern the order of code execution, but I have not been able to implement that solution successfully.
I would appreciate any insights and suggestions to help me resolve this issue. I am pasting the code snippet below.
Many thanks in advance.
export function iptSelectCompany_change ( event ) {
let activeUser = wixUsers . currentUser ;
let $item = $w . at ( event . context );
let myCompany = $item ( ‘#txtCompanyName’ ). text ;
**if** ( $item ( "#iptSelectCompany" ). checked ) {
wixData . insert ( "tmpDbSelect" , {
"userId" : activeUser ,
"selectedCompanies" : myCompany
});
} **else** {
wixData . query ( "tmpDbSelect" )
. eq ( "selectedCompanies" , myCompany )
. find ()
. then ( r => {
wixData . remove ( "tmpDbSelect" , r . items [ 0 ]. _id );
})
}
populateSelectCoRepeater ();
}
export function populateSelectCoRepeater ( ){
wixData . query ( “tmpDbSelect” )
. find ()
. then (( results ) => {
$w ( “#rptSelectedCompanies” ). data = results . items ;
})
}