我正在通过XML导入一些信息;下面是一组信息的示例(对于“项目”),尽管最终应用程序中最多可以有30-40个:
<phases>
<project>
<dbID>15</dbID>
<workingTitle>Motherfuckers</workingTitle>
<projName>5f3-2011</projName>
<startDate>8/10/2011</startDate>
<preprod>1</preprod>
<prod>2</prod>
<postprod>1</postprod>
<positions>
<position>
<startOffset>0</startOffset>
<numDays>4</numDays>
<role>PR</role>
<studentid>1193</studentid>
<conflict>0</conflict>
<studentType>bfa1</studentType>
</position>
<position>
<startOffset>0</startOffset>
<numDays>4</numDays>
<role>DR</role>
<studentid>1194</studentid>
<conflict>4</conflict>
<studentType>bfa1</studentType>
</position>
<position>
<startOffset>0</startOffset>
<numDays>4</numDays>
<role>WR</role>
<studentid>1194</studentid>
<conflict>4</conflict>
<studentType>bfa1</studentType>
</position>
<position>
<startOffset>0</startOffset>
<numDays>4</numDays>
<role>BO</role>
<studentid>1308</studentid>
<conflict>0</conflict>
<studentType>bfa1</studentType>
</position>
</positions>
</project>
</phases>
现在,我已经创建了一个函数来对所有XML信息进行排序,并将其存储在名为projectsAC的arrayCollection中。然后我创建了一个列表,其中包含“projectsAC”的数据提供者和“modules.project”的itemRenderer:
<mx:Canvas id="mainWrapper" width="100%" height="100%" y="90" verticalScrollPolicy="on" horizontalScrollPolicy="off">
<mx:VBox>
<mx:Canvas id="projectsWrapper" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:List id="projectsList" dataProvider="{projectsAC}" itemRenderer="modules.project" />
</mx:Canvas>
</mx:VBox>
</mx:Canvas>
项目模块如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:Scheduler="modules.*" layout="absolute" creationComplete="init();" dataChange="dataArray = data as Array" horizontalScrollPolicy="off">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private var dataArray:Array;
// project information
[Bindable] public var projectDBID:Number = 0;
[Bindable] public var workingTitle:String = new String;
[Bindable] public var projectNumber:String = new String;
[Bindable] public var startDate:Date = new Date;
[Bindable] public var positions:XML = new XML;
[Bindable] public var positionsAC:ArrayCollection = new ArrayCollection;
[Bindable] public var projectLength:Number = 0;
// container information
[Bindable] public var projectWidth:Number = 0;
[Bindable] public var projectX:Number = 0;
[Bindable] public var projectY:Number = 0;
private function init():void
{
if (dataArray)
getInfo(dataArray);
getProjLength();
getProjWidth();
getProjX();
}
public function getProjX():void
{
projectX = parentDocument.oneDay * parentDocument.dateDifference(parentDocument.startViewDate, startDate);
}
public function getProjWidth():void
{
projectWidth = parentApplication.oneDay * projectLength;
}
public function getProjLength():void
{
var tempLength:Number = 0;
var tempArray:Array = new Array;
for each (var position:Object in positions.position)
{
tempArray = new Array;
tempArray.push(position.startOffset);
tempArray.push(positions.numDays);
tempArray.push(positions.role);
tempArray.push(positions.studentid);
tempArray.push(positions.conflict);
tempArray.push(positions.studentType);
if (tempArray.length > 0)
positionsAC.addItem(tempArray);
if ((Number(position.startOffset) + Number(position.numDays)) > tempLength)
tempLength = Number(position.startOffset) + Number(position.numDays);
}
projectLength = tempLength;
}
private function getInfo(a:Array):void
{
a = fixA(a);
projectDBID = a[0];
workingTitle = a[1];
projectNumber = a[2];
startDate = parentApplication.textToDate(a[3]);
positions = XML(a[4]);
}
private function fixA(a:Array):Array
{
var toReturn:Array = a;
var toPush:String = "";
var pushLocation:Number = 0;
if (a.length > 5)
{
toReturn.push(a[pushLocation]); pushLocation++;
for (var i:int = pushLocation; i < a.length - 4; i++)
{
if (toPush != "")
toPush += ", ";
toPush += a[i];
pushLocation++;
}
toReturn.push(toPush);
for (i = pushLocation; i < 3; i++)
toReturn.push(a[i]);
}
return toReturn;
}
]]>
</mx:Script>
<mx:Canvas id="projectWrapper" backgroundColor="#000000" width="{projectWidth}" height="100%">
</mx:Canvas>
</mx:Module>
此代码返回以下结果显示:
我需要它看起来像这样:(当我使用中继器代替itemRenderers时它看起来如何)
在上图中,以蓝色突出显示的区域是项目包装器和紫色中概述的区域是该项目中我计划通过使用位置itemRenderer执行另一个列表来完成的位置。
任何人都可以提供一些帮助来解决这个问题。我真的不想再回到使用中继器,但我没有足够的时间浪费在试图解决这个问题上。 :(
提前致谢, BRDS
修改
@ M.D。 - 我根据您在评论中发布的内容对项目模块进行了以下更改。进行更改后,我加载了应用程序,没有任何项目显示:(
override protected function commitProperties():void
{
projectWrapper.width = projectWidth;
projectWrapper.x = projectX;
}
private function init():void
{
invalidateProperties();
if (dataArray)
getInfo(dataArray);
getProjLength();
getProjWidth();
getProjX();
invalidateProperties();
}