I am allowing a user to dynamically add items to a gallery. My code works for galleries that are not Wix Pro Galleries, but as soon as I change to a Wix Pro Gallery .items() returns Array(0) despite having an item in it. Is it possible at all to use .items() and I’m just doing something wrong, or does this not work with Wix Pro Gallery?
Hello,
Note that here are 2 differences when working with Pro Galleries in code:
-
A VideoItem can only be used as an item in a Pro Gallery.
-
You can only get the items of a Pro Gallery using the items property if you set its items using the items property or connect the gallery to a dataset first. If you set the gallery’s items in the Editor, you won’t be able to retrieve them with the items property. This limitation does not apply to standard galleries.
Make sure you are doing everything in accordance with the API and it should be working just fine.
https://www.wix.com/corvid/reference/$w.Gallery.html
Good luck!
This is a snippet of my code:
let items = $w("#gallery").items;
items.push({
"src": uploadfileurl,
"description": "",
"title": ""
});
$w("#gallery").items = items;
console.log($w("#gallery").items);
Any ideas why this always prints an empty array to the console? The behavior I am I getting is that the image is added to gallery but when I try to add another image it just overrides the first image