0

我实际上正在研究其他人的代码,但我无法弄清楚一些事情,我发现在 mxml 部分中访问数据提供者的方式非常特殊。

提取 1:

[Bindable] 
public var adrDataList:ArrayCollection = new ArrayCollection();

[Bindable]
public var obj:Object = new Object();

提取 2:

    adrDataList.getItemAt(0).id = null;
adrDataList.getItemAt(0).natureVoie = null;
adrDataList.getItemAt(0).numeroVoie = null;
adrDataList.getItemAt(0).nomVoie = null;
adrDataList.getItemAt(0).commune = null;
adrDataList.getItemAt(0).complementAdresse = null;
adrDataList.getItemAt(0).codePostal = null;
    obj.index = i;          
    obj.statutGeocodage = _model.service.getItemAt(i).statutGeocodage;
    obj.coordX = "484646868"
    obj.coordY = "455446846"                    
    adrDataList.addItemAt(obj, 0);

这是 mxml 部分:

<view:CustomDataGrid id="dgAdr" height="80" width="989" allowMultipleSelection="true"
    editable="{_model.isGeocodageActif}" 
    styleName="DataGrid" dataProvider="{adrDataList}" itemEditEnd="onEditItem(event)">
    <view:columns>
        <mx:DataGridColumn headerText="NumeroVoie" dataField="numeroVoie"/>
        <mx:DataGridColumn headerText="NatureVoie" dataField="natureVoie"/>     
        <mx:DataGridColumn headerText="NomVoie" dataField="nomVoie"/>
        <mx:DataGridColumn headerText="Commune" dataField="commune"/>
        <mx:DataGridColumn headerText="CodePostal" dataField="codePostal"/>
        <mx:DataGridColumn headerText="Géocod" editable="false">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Text text="{(data.coordX == 0)? '' : data.coordX} - {(data.coordY == 0)? '' : data.coordY}" />
                </mx:Component>
            </mx:itemRenderer>          
        </mx:DataGridColumn>
        <mx:DataGridColumn headerText="Géocodage" editable="false"   dataField="statutGeocodage">
                    <mx:itemRenderer>
                        <mx:Component>
                            <formatter:geocodBtn color="{data.statutGeocodage}" horizontalAlign="center"
                                enabledBtns="{outerDocument._model.isGeocodageActif}"
                                click="outerDocument.onGeoClick(data.id, data.numeroVoie, data.natureVoie, data.nomVoie, data.commune, data.codePostal, data.idTechnicien, data.complementAdresse,event)">
                            </formatter:geocodBtn>
                        </mx:Component>
                    </mx:itemRenderer>
        </mx:DataGridColumn>        
    </view:columns>
</view:CustomDataGrid>

我不明白为什么 data.coordX 正在工作?不应该是 data.obj.coordX

谢谢

Ps:我正在使用 flex SDK 3.5

4

2 回答 2

1

班级:

    package
{
    public class AdrObject
    {
         public var id:Number;
         public var natureVoie:Number;
         public var numeroVoie:Number;
         public var nomVoie:Number;
         public var commune:Number;
         public var complementAdresse:String;
         public var codePostal:String;
         public var internalObj:Object; //or may be other, such as InternalAdrObject type

        public function AdrObject()
        {
        }

        public function get g_coordX():Number{
            return internalObj.coordX;
        }
    }
}

xml:

    <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable] 
            [ArrayElementType("AdrObject")] 
            public var adrDataList:ArrayCollection = new ArrayCollection();
            [Bindable]
            public var obj:Object = new Object();

            public function init():void{
                var obj1:AdrObject = new AdrObject();
                var obj2:Object = new Object();
                obj1.id = null;
                obj1.natureVoie = null;
                obj1.numeroVoie = null;
                obj1.nomVoie = null;
                obj1.commune = null;
                obj1.complementAdresse = null;
                obj1.codePostal = null;
                obj2.index = 1;          
                obj2.statutGeocodage = 123;
                obj2.coordX = "484646868"
                obj2.coordY = "455446846"                    
                obj1.internalObj = obj2;
                adrDataList.addItem(obj1);
            }

        ]]>
    </mx:Script>

    <mx:DataGrid id="grid" width="100%" height="100%" dataProvider="{adrDataList}">
        <mx:columns>
            <mx:DataGridColumn dataField="g_coordX"/>       
        </mx:columns>   
    </mx:DataGrid>
</mx:Application>
于 2013-06-05T14:29:43.180 回答
0

您是指 {data.coordX} 部分吗?“obj”是绑定到该属性的数据。Obj 有它自己的属性“coordX”,可以通过 data.coordX 访问

[Bindable]
public var obj:Object = new Object();

请参阅Flex3 帮助中的 DataBinding

于 2013-06-04T08:36:56.653 回答