Leonardo Valentin Zeferino
Posts: 0
Joined: Fri May 29, 2015 2:07 pm

Change the css class with the mapping result

Hi!

I'd like a suggestion.

I need to read a field from database and depending what is the value, I need to load a CSS class in a DIV.

I know read the field from database but I don't know how can I read this value and define the css class.

I'm trying to read the field and change the class with the code bellow in the html file but the if clause isn't working.

code
<script>
if (Apperyio('wishlist_status')&#46;textl() == "55600a7fe4b0f840f328ab8f") {
$( '#product_wishlist_bt' )&#46;removeClass( 'product-bookmark' );
$( '#product_wishlist_bt' )&#46;addClass( 'product-bookmarked' );
}
</script>
/code

Thanks!

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

Change the css class with the mapping result

Hello,

There are no textl() method. Please use text() instead.

Leonardo Valentin Zeferino
Posts: 0
Joined: Fri May 29, 2015 2:07 pm

Change the css class with the mapping result

Sorry, @Sergiy.

I fixed "text()" without success. Same result.

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

Change the css class with the mapping result

Could you show screenshow with mapping with this JS code?

Leonardo Valentin Zeferino
Posts: 0
Joined: Fri May 29, 2015 2:07 pm

Change the css class with the mapping result

Hi Sergiy!

I'm using the screenshow. I'm programming direct in js and html code.

Look my code bellow:

product.js

code
Apperyio&#46;mappings["product_readWishlist_onsuccess_mapping_0"] = {
"homeScreen": "product",
"directions": [

Code: Select all

     { 
         "from_name": "readWishlist", 
         "from_type": "SERVICE_RESPONSE", 

         "to_name": "product", 
         "to_type": "UI", 

         "mappings": [ 

         { 

           "source": "$['body'][0]['_id']", 
           "target": "$['wishlist_status:text']" 

         } 
         ] 
     } 

     ] 
 }; 

/code

product.html

code
<div class="product-rating">
<div class="product-bookmark" name="wishlist_bt" id="product_wishlist_bt" dsid="wishlist_bt">
<a href="#">
<i class="zmdi zmdi-bookmark"></i>
</a>
<><!-- /&#46;product-bookmark -->
<script>
if (Apperyio('wishlist_status')&#46;text() == "55600a7fe4b0f840f328ab8f") {
$( '#product_wishlist_bt' )&#46;removeClass( 'product-bookmark' );
$( '#product_wishlist_bt' )&#46;addClass( 'product-bookmarked' );
console&#46;log("bookmarked");
}
</script>
/code

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

Change the css class with the mapping result

Does this code execute? Could you move it to the JS file instead of HTML component

Leonardo Valentin Zeferino
Posts: 0
Joined: Fri May 29, 2015 2:07 pm

Change the css class with the mapping result

Hi Sergiy!

The code executes. But not the if clause because I can't read the text/value of "whishlist_status" label/variable. I show it in the page but I can't use it in my code.

I tried too Apperyio('wishlist_status').val() because I'm comparing with an ID but without success.

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

Change the css class with the mapping result

Is it ("wishlist_status") Appery.io label component? Could you show us screenshot with it?
Could you clarify have you changed anything on Source tab? This (http://devcenter.appery.io/tutorials/...) doc should help.

Leonardo Valentin Zeferino
Posts: 0
Joined: Fri May 29, 2015 2:07 pm

Change the css class with the mapping result

Hi Sergiy!

6 days and you didn't understand my problem yet.

I'm programming directly in source tab and there isn't any possibility to not use the source tab. Suggestions like "make refresh" in source code isn't an option. I need to program directly in source code because my layout is customized.

Yes, "wishlist_status" is a Appery.io label component.
I just want to get the value of this component and use it in a javascript code.

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

Change the css class with the mapping result

If you change source code - you get your custom code. We are very sorry, but this is something outside the scope: http://devcenter.appery.io/support-po... of our support.

Return to “Issues”