hi
I’ve a newbie question please.
I have a repeater and a collection both connected to #dataset1.
I would like to iterate through the collection items where syntaxItem would be an iterator.
is this the right way to do it? it seems that syntaxItem gets only the first element…
thanks a lot
$w.onReady(() => { $w(“#dataset1”).onReady( () =>
{
let syntaxItem = $w(“#dataset1”).getCurrentItem();
//some item manipulation…
});
})
The getCurrentItem() function doesn’t get the first item, it, umm, gets the currrent item. If you want to iterate through all of the items, you could use the function getTotalItems() to find out how many items are in the dataset, and them use the getItems() function to return all of the items in the dataset. You can then loop through the returned items one at a time doing whatever it is you want to do. Note that this might not be the best approach if you have a large number of items.
Other options include having a loop that uses hasNext() and next() to iterate through the items in the dataset.
If you have a very large number of items in the dataset, you might opt to use the dataset’s page functions and process one page at a time. Or, you might just find using the wix-data API more efficient.
In other words, you’ve got lots of options. Have fun.
hey @yisrael-wix , thx .
I want to clarify myself. I want to iterate through the items of a existing collection before it is printed to my repeater when page loads. I thought that for each item in my collection the
$w(" #dataset1 ").onReady() is called by the “system” when it first loads the page. actually what does it mean the getcurrentItem when the page and dataset have just loaded
$w.onReady(() => { $w("#dataset1").onReady( () =>
{
let syntaxItem = $w("#dataset1").getCurrentItem();
thx again