Hi, i am trying to have a button on my page, which would randomly access one of x number of items in an array. I got the script, but it doesn’t work the way i think it should, here are the issues:
1 . The script does access the array, but it sees only the last 50 added items to a data set. No matter how many items i have (if more than 50), it only sees the last 50.
The button only works in the preview mode of my web. On the live web the browser doesn’t even recognize it as a button.
Here is the code:
import wixLocation from 'wix-location';
import wixData from 'wix-data';
export function button3_click(event) {
let links = [];
wixData.query('test').find().then((results) => {
results.items.forEach((item) => {
let link = "/test/" + item.title
links.push(link)
let linker = links[Math.floor(Math.random() * links.length)]
wixLocation.to(linker);
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}
@mennyg19 I’m not sure, will have to check that later, but i am wondering if there is an option to enable or disable button? I think it’s only wether it’s linked to a page or not.
@kaikarisjonas if you right click the element and click properties on the bottom of the drop-down menu, it will popup a small menu. One of the options in the menu is to be enabled or disabled by default.
@jonatandor35 If i link it to any page (i.e. Home page) the button works. My working process was simple: add the button, enable on-click function and write the code. Anything else i should have done?