我有一个具有以下结构的arrayCollection:
projectErrorsAC
0
project1number
project2number
position1number
position2number
project1name
project2name
student
1
...
AC 定义如下:
[Bindable] private var projectErrorsAC:ArrayCollection = new ArrayCollection;
我在中继器中使用这个交流电来显示每个错误。在显示每个错误后,我放置了一个“接受”和“拒绝”按钮。一旦用户单击这些按钮中的任何一个,我想调用一个从 AC 中删除特定错误的函数。这是我到目前为止所拥有的:
中继器:
<mx:Repeater id="projRP" width="100%" dataProvider="{projectErrorsAC}">
<mx:HBox>
<mx:Text id="projmsg" text="{projRP.currentItem.student} is working on the following projects on the same day: {projRP.currentItem.proj1name} and {projRP.currentItem.proj2name}." />
<mx:Text id="allow" text="Allow" color="#ff0000" selectable="false"
click="acceptProjConflict(projRP.currentItem);"
mouseOver="parentApplication.switchCursor(true);"
mouseOut="parentApplication.switchCursor(false);" />
<mx:Text text=" |" />
<mx:Text id="decline" text="Decline" color="#ff0000" selectable="false" click="declineProjConflict(projRP.currentItem);" mouseOver="parentApplication.switchCursor(true);" mouseOut="parentApplication.switchCursor(false);" />
</mx:HBox>
</mx:Repeater>
这是我在“点击”部分调用的函数:
public function acceptProjConflict(conflict:Object):void
{
for (var i:int = 0; i < projectErrorsAC.length; i++)
{
if (projectErrorsAC.getItemAt(i) == conflict)
projectErrorsAC.removeItemAt(i);
}
}
由于某种原因,这不起作用...
* 编辑 *
成功!
我必须创建一个模块来放入中继器 - 中继器现在看起来像这样:
<mx:Repeater id="projRP" width="100%" dataProvider="{projectErrorsAC}">
<conflict:showErrors id="projErrors" thisObject="{projRP.currentItem}" isProject="true"/>
</mx:Repeater>
我的模块看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Script>
<![CDATA[
public var isProject:Boolean;
public var thisObject:Object;
[Bindable] public var displayString:String = new String;
private function init():void
{
if (isProject)
{
displayString = thisObject.student + " is working on the following projects on the same day: " + thisObject.proj1name + " and " + thisObject.proj2name + ".";
}
}
]]>
</mx:Script>
<mx:Canvas width="750">
<mx:HBox>
<mx:Text id="projmsg" text="{displayString}" />
<mx:Text id="allow" text="Allow" color="#ff0000" selectable="false" click="parentDocument.acceptProjConflict(thisObject)" mouseOver="parentApplication.switchCursor(true);" mouseOut="parentApplication.switchCursor(false);" />
<mx:Text text=" |" />
<mx:Text id="decline" text="Decline" color="#ff0000" selectable="false" click="parentDocument.declineProjConflict(thisObject);" mouseOver="parentApplication.switchCursor(true);" mouseOut="parentApplication.switchCursor(false);" />
</mx:HBox>
</mx:Canvas>
</mx:Module>