Appcelerator sidemenu redirect to another screen c

2019-08-12 01:52发布

问题:

I am using this sidemenu module in my app.

In sidemenu i have option like home, setting etc. When i click on setting, it redirect to setting page. Now problem is when setting page is opened and i open side menu using swipe and again click on setting then it will again open setting screen on previous one. Means it creating 2 setting screen. If i repeat it again then it will creating again setting scree. How do i prevent this?

My code for screen redirection is here

var win = Alloy.createController('Setting').getView();
window.closeOpenView();
$.navWindow.openWindow(win);

回答1:

Store last opened page:

Add this outside the click function

var openWindow = '';

And this inside the click function

if (openWindow == 'Setting') return;

openWindow = 'Setting'
var win = Alloy.createController('Setting').getView();
window.closeOpenView();
$.navWindow.openWindow(win);

This assumes this is in a function, which I guess it is because it is a click handler. If not, wrap it in a function