Is there any new update on wix that screwed up the repeaters?
The on item ready code is not applying the code on every item. When I print the results with console.log, it’s working fine. But the items on the repeater are not working. It is just taking the first result and applying it to all items in the repeater. What’s going on?
I have worked with repeaters for a long time now.
See attached. You can see it is giving me three items, but same name for example. and even the other parameters on the list (like address) - the same.
I do check with console.log to see the item name, and it is giving the right items in the right orders - but not on the repeater!
import wixData from ‘wix-data’;
$w.onReady(function () {
$w(“#repeater2”).onItemReady( ($item, itemData, index) => {
console.log(itemData.name)
$w(‘#text12’).text = itemData.name
$w(‘#text10’).text = itemData.address
$w(‘#text11’).text = itemData.price
$w(‘#image1’).src = itemData.image
})
wixData.query(“restaurants”)
.contains(“city”, city)
.eq(‘live’, true)
.find()
.then((results) => {
$w('#repeater2').data = results.items
})
});
the parameter “city” i get it from the session btw. it can be replaced, still no result!
Btw, this was working normally on the repeater a couple of days ago!
You need to use the Repeated Item Scope ($item) in your onItemReady() function.
Sorry I am a bit confused. Why? I’ve used repeaters always like this and they worked. What changed?
At one time you would have done this:
$w("#repeater2").onItemReady( ($w, itemData, index) => {
console.log(itemData.name)
$w('#text12').text = itemData.name
$w('#text10').text = itemData.address
$w('#text11').text = itemData.price
$w('#image1').src = itemData.image
})
The first parameter passed in the onItemReady() is the scope. You’ll notice that the example code I am passing $w. That might theoretically work. However, you were passing $item which causes $w to have a global scope.
However the above method was deprecated and this is the new way:
$w("#repeater2").onItemReady( ($item, itemData, index) => {
console.log(itemData.name)
$item('#text12').text = itemData.name
$item('#text10').text = itemData.address
$item('#text11').text = itemData.price
$item('#image1').src = itemData.image
})
Note that in this case, the first parameter is $item, but in this example, $item is used for all values to be set.
Ok I see what’s happening. Sorry. Thanks.