简体   繁体   中英

Updating itemrenderer dataprovider

I am creating an opensource application for managing environmental resources in my county.

I have a problem on a dataprovider for an itemrenderer (combobox) i am using on a datagrid. The application works, but I get a warning saying the itemrenderer dataprovider will not be reassigned data on its update with a setter. Even if I do not need to reassign the combobox itemrenderer dataprovider, for a matter of best practice I would like to solve this warning.

This is the usual code I use for getting dataprovider data as an array collection populated from the result of a web service in the parentDocument of the itemrenderer:

//set farmers arrayCollection values for combobox itemrenderer
    [Bindable]
    private var _acFarmers:ArrayCollection=new ArrayCollection;
    public function set acFarmers(acFarmers:ArrayCollection):void{
        _acFarmers=acFarmers;

    }
    //get machines ArrayCollection values
    public function get acFarmers():ArrayCollection{
        return _acFarmers;
    }

This is the code for the datagrid itemrenderer (showing only the interested column of the datagrid):

<mx:DataGridColumn headerText="Agricoltore" dataField="farmerId" width="200" rendererIsEditor="true" editable="false">

            <mx:itemRenderer>

                <fx:Component id="cmpCmbFarmers">

                        <mx:HBox>

                        <s:ComboBox width="200" 
                                    id="cmbFarmers"
                                    dataProvider="{outerDocument.acFarmers}" 
                                    labelField="companyName" 
                                    change="onSelectionChange(event)"

                                    >
                            <fx:Script>
                                <![CDATA[
                                    import mx.controls.dataGridClasses.DataGridListData;
                                    import mx.controls.listClasses.BaseListData;
                                    import mx.events.ListEvent;

                                    private var _ownerData:Object;

                                    private function setSelected():void {

                                    }

                                    override public function set data(value:Object):void{
                                        if(value != null)  {
                                            super.data=value;
                                            _ownerData=value;

                                            if(value.collectingMachineId!==null){
                                                for each(var dp:Object in cmbFarmers.dataProvider){
                                                    var dpFarmerId:String=dp.farmerId
                                                    var dataFarmerId:String=value.farmerId;
                                                    if(dpFarmerId==dataFarmerId){
                                                        cmbFarmers.selectedItem=dp;
                                                    }
                                                }
                                            } else {
                                                cmbFarmers.selectedIndex=0;
                                                data.farmerId=cmbFarmers.selectedItem.farmerId;
                                            }
                                        }
                                    }


                                    import spark.events.IndexChangeEvent;

                                    protected function onSelectionChange(event:IndexChangeEvent):void
                                    {

                                        data.farmerId=cmbFarmers.selectedItem.farmerId;
                                    }     



                                ]]>
                            </fx:Script>
                            </s:ComboBox>

                        </mx:HBox>


            </fx:Component> 
            </mx:itemRenderer>

            </mx:DataGridColumn>

This code works if I call the itemrenderer service to get combobox data BEFORE calling the datagrid data service and setting the datagrid arraycollection at re response of the service.

BUT a warning is displayed because the combobox dataprovider will not get changes after a set function on its dataprovider (_acFarmers).

This is the only warning I have on an entire project but i did not manage how to solve it.

I would really appreciate any help.

Thanks

Paolo

You have to put [Bindable] metatag above your setter instead of above _acFarmers . Because right now your acFarmers property is not the source for data binding.

Or better use just public variable instead of getter and setter since you didn't implement other actions in them.

Link about databinding

Try to use dataChangeEvent you can use the dataChange event with an item renderer or item editor. Flex dispatches the dataChange event every time the data property changes.

<mx:ItemRenderer dataChange="someFunction()">

or

dataToDisplay.addEventListener( FlexEvent.DATA_CHANGE, dataChange );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM