EnnSie
Posts: 0
Joined: Fri Mar 20, 2015 7:17 am

Compare lowest value

Image

How can I compare price from store1 and store2? do i use javascript for that?
I want it to display in a list, so every list will show the lowest item by changing highlighting the font to red or green color. in the picture are the sample of database and below picture are the sample output
Image

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Compare lowest value

Due to you are using a list service,
you can store the difference between two prices (Compare price from Sotre 1 and 2) in the localStorage and show it as a label.
code
var price1=Apperyio('Price1').text();
var price2=Apperyio('Price2').text();
localStorage.setItem("Compare",price1-price2);
Apperyio('Compare_Label').text(Compare);/code

EnnSie
Posts: 0
Joined: Fri Mar 20, 2015 7:17 am

Compare lowest value

what if I want to compare more than 3 prices?

localStorage.setItem("Compare",price1-price2-price3-price4-price5);
Apperyio('Compare_Label').text(Compare);

is that correct?

I tried to run the script but error - "Uncaught ReferenceError: Compare is not defined"
came out

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Compare lowest value

"Uncaught ReferenceError: Compare is not defined" happened probably because you didn't have a storage variable called "Compare"
"Compare" is a local Storage variable which you use and fill the name of that variable in "Compare"
If you don't understand, then just create an variable called "Compare" at "Model and Storage" at "App Settings" in App Editor

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Compare lowest value

Sorry, I think I misunderstand your request (or maybe you change it)
So I change the code a little bit,
code
var price1=Apperyio('Price1').text();
var price2=Apperyio('Price2').text();
if (price1-price2 >0){
Appery('Price1').css("color", "red");
}
else{
Appery('Price2').css("color", "red");
}

/If Price 1 smaller than price 2, then answer will be negative/
/code

EnnSie
Posts: 0
Joined: Fri Mar 20, 2015 7:17 am

Compare lowest value

I created at Model and Storage a variable called 'Compare' below are my coding:
var p1=Apperyio('price1').text();
var p2=Apperyio('price2').text();
var p3=Apperyio('price3').text();
var Compare = Apperyio('Compare');

localStorage.setItem("Compare",p1-p2-p3);
Apperyio('compareLabell').text(Compare);

There is no more error but output still blank.

EnnSie
Posts: 0
Joined: Fri Mar 20, 2015 7:17 am

Compare lowest value

it works but only for the first item list.. Image

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Compare lowest value

Remember, P1-P2-P3 will give you negative answer
(1 price minus 2 prices)
Check out the new code I've post below, ignore the code with /If Price 1 smaller than price 2, then answer will be negative/

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Compare lowest value

Figuring it out, ASAP(Because I'm not an employee!)
At this time, you may want to check out this link:
https://devcenter.appery.io/documenta...

Mark Wong
Posts: 0
Joined: Sat Feb 14, 2015 7:47 am

Compare lowest value

Easiest Way and Stupiest Way XD
This is for 3 prices comparing
If you want to do it on list item put them on the mapping JS
var p1=Apperyio('price1').text();
var p2=Apperyio('price2').text();
var p3=Apperyio('price3').text();
code
if (price1<price2) {
if (price1<price3) {
Appery('price1')&#46;css("color", "red");}}

if (price2<price1) {
if (price2<price3) {
Appery('price2')&#46;css("color", "red");}}

if (price3<price1) {
if (price3<price2) {
Appery('price3')&#46;css("color", "red");}}/code

Return to “Issues”