Mike Kastens
Posts: 0
Joined: Sun Jul 26, 2015 7:27 pm

Navigate to correct page form list item populated from database?

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Navigate to correct page form list item populated from database?

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

Mike Kastens
Posts: 0
Joined: Sun Jul 26, 2015 7:27 pm

Navigate to correct page form list item populated from database?

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.

Mike Kastens
Posts: 0
Joined: Sun Jul 26, 2015 7:27 pm

Navigate to correct page form list item populated from database?

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?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Navigate to correct page form list item populated from database?

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

Mike Kastens
Posts: 0
Joined: Sun Jul 26, 2015 7:27 pm

Navigate to correct page form list item populated from database?

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

Return to “Issues”