2nd next previous button

I set 2 dynamic page at 1 page. And use List & grid.
I want to set next previous button each dynamic pages.
The 1 page does work, but the other one does not work.

Please teach me the way to write the code.

【List page】
import {local} from ‘wix-storage’;
import wixWindow from ‘wix-window’;

const linkField = “link-control-page-title-2”;

$w.onReady(function () {
if(wixWindow.rendering.env === “browser”) {
$w(“#dataset1”).onReady(() => {
const numberOfItems = $w(“#dataset1”).getTotalCount();

  $w("#dataset1").getItems(0, numberOfItems) 
    .then( (result) => {  
      const dynamicPageURLs = result.items.map(item => item[linkField]); 
      local.setItem('control-page/{Title}', dynamicPageURLs); 
    } ) 
    .catch( (err) => { 
      console.log(err.code, err.message); 
    } ); 
} ); 

}
} );

import wixWindow from ‘wix-window’;
$w.onReady( function () {
if(wixWindow.formFactor === “Mobile” &&
wixWindow.rendering.renderCycle === 1) {
$w(“#button2”).hide();
$w(“#button4”).hide();
}
} );

import {local} from ‘wix-storage’;
import wixWindow from ‘wix-window’;

const linkField = “link-control-page-recomand-category”;

$w.onReady(function () {
if(wixWindow.rendering.env === “browser”) {
$w(“#dataset2”).onReady(() => {
const numberOfItems = $w(“#dataset2”).getTotalCount();

  $w("#dataset2").getItems(0, numberOfItems) 
    .then( (result) => {  
      const dynamicPageURLs = result.items.map(item => item[linkField]); 
      local.setItem('control-page/recomand/{Title}', dynamicPageURLs); 
    } ) 
    .catch( (err) => { 
      console.log(err.code, err.message); 
    } ); 
} ); 

}
} );

【top item page】
import {local} from ‘wix-storage’;
import wixWindow from ‘wix-window’;

const linkField = “link-control-page-title-2”;

$w.onReady(function () {
if(wixWindow.rendering.env === “browser”) {
$w(“#dataset1”).onReady(() => {
const numberOfItems = $w(“#dataset1”).getTotalCount();

  $w("#dataset1").getItems(0, numberOfItems) 
    .then( (result) => {  
      const dynamicPageURLs = result.items.map(item => item[linkField]); 
      local.setItem('control-page/{Title}', dynamicPageURLs); 
    } ) 
    .catch( (err) => { 
      console.log(err.code, err.message); 
    } ); 
} ); 

}
} );

【2nd item page】
import {
local
}
from ‘wix-storage’;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;

$w.onReady(function () {
if (wixWindow.rendering.env === “browser”) {
$w(“#button9”).disable();
$w(“#button10”).disable();

	if (local.getItem('control-page/recomand/{Title}')) { 
		const dynamicPageURLs = local.getItem('control-page/recomand/{Title}').split(','); 

		const currentPage = '/' + wixLocation.prefix + '/' + wixLocation.path.join('/'); 
		const currentPageIndex = dynamicPageURLs.indexOf(currentPage); 

		if (currentPageIndex > 0) { 
			$w("#button9").link = dynamicPageURLs[currentPageIndex - 1]; 
			$w("#button9").enable(); 
		} 

		if (currentPageIndex < dynamicPageURLs.length - 1) { 
			$w("#button10").link = dynamicPageURLs[currentPageIndex + 1]; 
			$w("#button10").enable(); 
		} 
	} 
} 

});

Hi,

i’d recommend that for troubleshooting reasons, you remark parts of the code which handles mobile vs desktop and server side rendering vs browser and then compare between the two pages, seems there is too much going on in parallel at the moment :slight_smile:

if the issue still persists after you simplify the scenario, please share here the url you are trying to build

Shlomi

Hi Shlomi thnak you your reply!
Its solved.

In top page use 2 “linkField”
So I change the name “linkField1” and “linkField2”

import {
local
}
from ‘wix-storage’;
import wixWindow from ‘wix-window’;

const linkField1 = “link-control-page-title-2”;

$w.onReady(function () {
if (wixWindow.rendering.env === “browser”) {
$w(“#dataset1”).onReady(() => {
const numberOfItems = $w(“#dataset1”).getTotalCount();

		$w("#dataset1").getItems(0, numberOfItems) 
			.then((result) => { 
				const dynamicPageURLs = result.items.map(item => item **[linkField1]** ); 
				local.setItem('control-page/{Title}', dynamicPageURLs); 
			}) 
			.catch((err) => { 
				console.log(err.code, err.message); 
			}); 
	}); 
} 

**const linkField2**  = "link-control-page-recomand-category"; 

if (wixWindow.rendering.env === "browser") { 
	$w("#dataset2").onReady(() => { 
		const numberOfItems = $w("#dataset2").getTotalCount(); 

		$w("#dataset2").getItems(0, numberOfItems) 
			.then((result) => { 
				const dynamicPageURLs = result.items.map(item => item **[linkField2]** ); 
				local.setItem('control-page/recomand/{Title}', dynamicPageURLs); 
			}) 
			.catch((err) => { 
				console.log(err.code, err.message); 
			}); 
	}); 
} 

if (wixWindow.formFactor === "Mobile" && 
	wixWindow.rendering.renderCycle === 1) { 
	$w("#button2").hide(); 
	$w("#button4").hide(); 
} 

});