Page 1 of 2

If else statement in Barcode scan result

Posted: Tue Jan 06, 2015 4:32 am
by Ben7311441

I already make a Barcode scanner, the result after it scan the barcode is in text (example - "page 2").
My problem is how do i want create event on the result.
That result will determine which page the application will display.

Example :

Result Name of Page
"page 1" Home
"page 2" Activity 1
"page 3" Activity 2

So what kind of script do i have to put on the barcode scanner?

*Result is the text result after barcode is scanned


If else statement in Barcode scan result

Posted: Tue Jan 06, 2015 5:28 am
by Yurii Orishchuk

Hi Ben,

If i understand you correctly you can use following JS code:

pre

//Here is your result.
var result = "page 2";

var pageMapping = {
"page 1": "Home",
"page 2": "Activity 1",
"page 3": "Activity 2"
};

var goalPage = pageMapping[result];

console.log("result = " + result);
console.log("goalPage = " + goalPage);

Apperyio.navigateTo(goalPage);

/pre

Regards.


If else statement in Barcode scan result

Posted: Tue Jan 06, 2015 7:33 am
by Ben7311441

Thanks for your reply. Really appreciate that.
Here some idea of what i actually want but don't know how to implement it in apperyio. Hope you can help:

*After barcode scanner scanned the barcode, its result stored in "Data".
{
if (Data=="page1")
navigateTo(page1);
else if(Data=="page2")
navigateTo(page2);
else
display ("There is no such data");
}

And where do i have to put the JS, is it in the barcodescanner element?


If else statement in Barcode scan result

Posted: Tue Jan 06, 2015 11:21 pm
by Yurii Orishchuk

Hi Ben,

You should use this code where you have data from your barcodescanner. Or rather, you must pass result from scanner to "result" variable.

pre

//Here you should specify your dynamic Data instead of "page 2".
//var result = "page 2";

//This is settings compliance between data stored in "result" variable and page that you need to navigate to.
var pageMapping = {
"page 1": "Home",
"page 2": "Activity 1",
"page 3": "Activity 2"
};
var goalPage = pageMapping[result];

console.log("result = " + result);
console.log("goalPage = " + goalPage);

if(goalPage)
Apperyio.navigateTo(goalPage)
else
alert("There is no such data");

/pre

Also you can see some intermediate debug data. Read more about debugging here: http://devcenter.appery.io/documentat...

Regards.


If else statement in Barcode scan result

Posted: Wed Jan 07, 2015 11:32 pm
by Ben7311441

Sorry if i am asking too much sir.. I already understand the rest of the code u mentioned, and I thankful for that. But.. i am a bit confused with the 1st code line.. the result you initialized as "page 2". How to make result be initialized directly with value from barcode scanner..

1) How do I pass the result from scanner to result variable?
2) And you stated there I need to specify dynamic data instead "page 2". How can I specify that dynamic data? I already created new storage variable(local storage) and i named it DATA. is that dynamic data that you mentioned? If yes, instead of you initialized value result as "page 2", should I do like this:

var result = "DATA" or var result = DATA

Thank you sir. Much appreciate.


If else statement in Barcode scan result

Posted: Thu Jan 08, 2015 1:50 am
by Ben7311441

I did this, i already created variable in local storage named DATA. result of barcode scanner will mapped on DATA . Then I put this JS code on that DATA :

var pageMapping = {
"page 1": "Home",
"page 2": "Activity 1",
"page 3": "Activity 2"
};
var goalPage = pageMapping[DATA];
console.log("result = " + DATA);
console.log("goalPage = " + goalPage);
if(goalPage)
Apperyio.navigateTo(goalPage);
else
alert("There is no such data");

Still it didnt navigate.. (Below is the image how i map the data of barcode scanner)


If else statement in Barcode scan result

Posted: Thu Jan 08, 2015 1:58 am
by Ben7311441

If else statement in Barcode scan result

Posted: Thu Jan 08, 2015 4:43 am
by Yurii Orishchuk

Hi Ben,

Okay, you have stored result into the "DATA" storage.

In this case code should be:

pre

//Where "DATA" is your storage name.
var result = Apperyio.storage.DATA.get();

//This is settings compliance between data stored in "result" variable and page that you need to navigate to.
var pageMapping = {
"page 1": "Home",
"page 2": "Activity 1",
"page 3": "Activity 2"
};
var goalPage = pageMapping[result];
console.log("result = " + result);
console.log("goalPage = " + goalPage);
if(goalPage)
Apperyio.navigateTo(goalPage)
else
alert("There is no such data");

/pre

Regards.


If else statement in Barcode scan result

Posted: Fri Jan 16, 2015 12:38 am
by Ben7311441

I did paste this code in JS space in local storage DATA. but when i run barcode scanner, i scanned "page 1", it didnt navigate me to "Home" page, and end up display "there is no such data". May i know which part that i did it wrong? I attached images of screen shot here.


If else statement in Barcode scan result

Posted: Fri Jan 16, 2015 12:39 am
by Ben7311441