Thanks for the code. No syntax errors, but I’m not even able to call the function. I guess I just don’t understand how the Wix architecture works. It’s been a long time since I coded websites, and that was done with Microsoft’s .net, with an integrated development environment where I could debug. With Wix, I just don’t understand how to do that.
Here’s my code:
import wixData from ‘wix-data’ ;
$w . onReady ( function () {
// Write your JavaScript here
// To select an element by ID use: $w(‘#elementID’)
// Click ‘Preview’ to run your code
});
/* from Bruno Prado */
export const copyRowsCount = async () => {
let query = await wixData . query ( ‘Source’ ). limit ( 10 ). find ()
let allItems = query . items
if ( allItems . length > 0 ) {
while ( query . hasNext ()) {
query = await query . next ()
allItems = [… allItems , … query . items ]
}
} // This is going to retrieve all the items from the Source collection.
let results =
allItems . forEach (( item ) => {
for ( let i = 0 ; i < item . count ; i ++) {
results . push ( wixData . insert ( ‘Destination’ , { title : item . title , isbn : item . isbn }))
}
}) //This is going to select the items to be added.
await Promise . all ( results )
}
export function btnStart_click ( event ) {
copyRowsCount ;
}