Page 1 of 1

Navigate to correct page form list item populated from database?

Posted: Mon Jan 09, 2017 10:05 pm
by Mike Kastens

Hello,

I am creating an app that finds the correct sales representative for a company based on a zip code entered by the user. The user searches for the zip code, and the correct representative is located through performing a query on a database. All of this works fine. The issue is this:

I have a list that is populated with the rep name once it is found. This means there is only one item in the list but changes for different zip codes entered. Each rep has a unique page with rep information. I need to navigate to this page when the list item with the rep's name is selected by the user.

How can I do this? The navigate to page only works when the list item is selected, meaning that since there is only one list item, it just changes when the correct rep is found from the search, clicking on the list item, regardless of the name on it, would only be able to navigate to one page. How can I check which name is on the list item and navigate to its correct page?

Any help is much appreciated.


Navigate to correct page form list item populated from database?

Posted: Tue Jan 10, 2017 5:11 pm
by Serhii Kulibaba

Hello Mike,

You can use a switch statement, e.g.:
pre
var screenName = "";
switch(zip){
case "001":{
screenName = "Screen1";
break;
}
case "002":{
screenName = "Screen2";
break;
}
}
Apperyio.navigateTo(screenName);/pre

here "001" and "002" - zip codes and "Screen1", "Screen2" - names of pages, which are related to these zip codes


Navigate to correct page form list item populated from database?

Posted: Tue Jan 10, 2017 6:55 pm
by Mike Kastens

Thank you for your reply Sergiy. I have one other question. Is there a way to access the text on the list item and use that either in the switch statement or a nested if statement? My list items change based on a search so using a switch statement as above wouldn't quite work in this case.

Thanks again for the reply.


Navigate to correct page form list item populated from database?

Posted: Tue Jan 10, 2017 7:06 pm
by Mike Kastens

Sorry, I think I misunderstood. The "001" and "002" in your example are strings that are zip codes that would be the text on the list items correct? And the (zip) for the switch statement is the name of the list?


Navigate to correct page form list item populated from database?

Posted: Wed Jan 11, 2017 5:04 pm
by Serhii Kulibaba

You are right, do you need to read a text value of the list item? If so - please use JS below on the click event of the list item:
prevar zip = $(this).text();/pre


Navigate to correct page form list item populated from database?

Posted: Wed Jan 11, 2017 7:22 pm
by Mike Kastens

Thank you for your help. I couldn't get the switch statement to work properly but I used if statements and it works fine.