piotrzarzycki21 commented on issue #639: Binding doesn't work in Jewel List 
item renderers using VO
URL: https://github.com/apache/royale-asjs/issues/639#issuecomment-568587564
 
 
   I have made interesting observation. In our project I'm using following 
workaround to have it working:
   ```
   <?xml version="1.0" encoding="utf-8"?>
   <j:ListItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009";
                                         
xmlns:j="library://ns.apache.org/royale/jewel" 
xmlns:js="library://ns.apache.org/royale/basic">
        <fx:Script>
                <![CDATA[
                        [Bindable("dataChange")]
               public function get someVO():SomeVO
               {
                   return data as SomeVO;
               }
   
                        override public function set data(value:Object):void
                        {
                                if (super.data != value && super.data)
                                {
                                        
super.data.removeEventListener(ValueChangeEvent.VALUE_CHANGE, onDataChange);
                                }                       
                                super.data = value;
                                
                                if (super.data)
                                {
                                        
super.data.addEventListener(ValueChangeEvent.VALUE_CHANGE, onDataChange);
                                }       
                        }
                        
                        private function 
onDataChange(event:ValueChangeEvent):void
                        {
                                itemQuantity.text = String(someVO.itemQuantity);
                        }
                ]]>
        </fx:Script>
        <j:beads>
                <js:ItemRendererDataBinding />
        </j:beads>
        
        <j:HGroup percentWidth="100" percentHeight="100"
                itemsHorizontalAlign="itemsCentered" 
itemsVerticalAlign="itemsCentered">
                <j:Label localId="itemQuantity" text="{someVO.itemQuantity}" 
percentWidth="100"/>
        </j:HGroup>
   </j:ListItemRenderer>
   ```
   
   If my VO has `[Bindable]` on top of it `ValueChangeEvent.VALUE_CHANGE` is 
not being dispatched, so listener `onDataChange `is not called.
   ```
           [Bindable]
        public class SomeVO  
        {
           }
   ```
   
   If VO has `[Bindable]` on top on every property everything is working fine 
and `onDataChange` has been called.
   
   ```
        public class SomeVO  
        {
                public function SomeVO()
                {
                }
                        
                private var _itemQuantity:int = 1;
                
                [Bindable]
                public function get itemQuantity():int
                {
                        return _itemQuantity;
                }
   
                public function set itemQuantity(value:int):void
                {
                        _itemQuantity = value;
                }
        }
   ```
   
   Note that this change on VO won't fix original issue - I checked that. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to