wixLocation

Hi,
in my web page I have the following code to access the dynamic page:

export function table1_click(event, $w) {
	$w('#dataset2').onReady(() => {
		let newValue1 = $w('#dataset2').getCurrentItem()['field'];
		wixLocation.to('https://myprefix.wixsite.com/sitename/"FIELD DYNAMIC PAGE"/' + newValue1);
	});

On the pc it’s all right, but on smartphone it works only the first time I access the dynamic page.

I’ll explain

  1. If i come back to the calling page

  2. I call the dynamic page again with another key field (newValue1)

  3. Shows the dynamic page for the different key field

Why? Can you suggest me?

Thank you and sorry for my bad english

Add a console log to check when the dataset2 is ready so you might see if it is not ready the times it wont run.

export function table1_click(event, $w) { $w('#dataset2').onReady(() => { 
console.log("dataset 2 is ready");
let newValue1 = $w('#dataset2').getCurrentItem()['field']; 		wixLocation.to('https://myprefix.wixsite.com/sitename/"FIELD DYNAMIC PAGE"/' + newValue1); });

Hi,
You need to write the table’s onClick inside the dataset’s onReady, the on ready function runs only one time when the item is ready, and that is the reason the code works only on the first time.
The solution is to change the order of the function, make the click available only when the dataset is ready.
The code should look like this:

export function dataset2_ready() {
	$w('#table1').onClick((event, $w) => {
		let newValue1 = $w('#dataset2').getCurrentItem()['field'];
		wixLocation.to('https://myprefix.wixsite.com/sitename/"FIELD DYNAMIC PAGE"/' + newValue1);
	});
}

Good luck :slight_smile:

Hi,
there is an error on " let " and " event " undefined

Okay I changed the code and it should work now.
You should also define the function in the properties panel of the dataset, like this: