我实际上正在处理别人的代码,但我无法弄明白,我发现在mxml部分中访问dataprovider的方式非常特殊。
摘录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
答案 0 :(得分: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;
}
}
}
MXML:
<?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>
答案 1 :(得分:0)
你的意思是{data.coordX}部分吗? “obj”是绑定到该属性的数据。 Obj拥有自己的属性“coordX”,可以通过data.coordX
访问[Bindable]
public var obj:Object = new Object();