I have a repeater that has items loaded dynamically by calling a backend function. The items have to respond to onClick events and link to different locations based on their data.
In some cases, they need to show a local page in the same window and pass some data to it. I do that with saving the data to session storage and winLocation.to() . No problem there.
However, in some other cases, they need to open an external link in a new tab/window (I know it’s a browser thing, but you know what I mean. target=“_blank”). I understand that this cannot be done with winLocation.to() and, afaik, there is no LinkableMixin link/target for the item in the repeater’s onItemReady().
It thought of adding a collapsed text and setting it’s link/target, but I couldn’t find a way to simulate click() for it.
Any workaround?
Here is some code:
import wixLocation from 'wix-location';
import {session} from 'wix-storage';
import {getSomeData} from 'backend/data';
$w.onReady(() => {
getSomeData().then((data) => {
$w('#repeater').data = data;
});
});
export function repeater_itemReady($item, itemData, index) {
// Setting item's data here
}
export function repeaterItem_click(event) {
if (needToLinkToExternal(event.target)) {
// I NEED TO OPEN AN EXTERNAL LINK IN A NEW TAB HERE!
} else {
session.setItem('some_id', getSomeIdForItem(event.target));
wixLocation.to('/anotherpage');
}
}