Page 1 of 2

Compare lowest value

Posted: Fri Apr 17, 2015 6:43 am
by EnnSie

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


Compare lowest value

Posted: Fri Apr 17, 2015 7:10 am
by Mark Wong

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


Compare lowest value

Posted: Tue Apr 21, 2015 4:57 am
by EnnSie

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


Compare lowest value

Posted: Tue Apr 21, 2015 10:29 am
by Mark Wong

"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


Compare lowest value

Posted: Tue Apr 21, 2015 10:39 am
by Mark Wong

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


Compare lowest value

Posted: Tue Apr 21, 2015 10:41 am
by EnnSie

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.


Compare lowest value

Posted: Tue Apr 21, 2015 11:01 am
by EnnSie

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


Compare lowest value

Posted: Tue Apr 21, 2015 11:04 am
by Mark Wong

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/


Compare lowest value

Posted: Tue Apr 21, 2015 11:11 am
by Mark Wong

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...


Compare lowest value

Posted: Tue Apr 21, 2015 11:23 am
by Mark Wong

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