Flex 3:添加子项后刷新中继器

发布于 2024-11-09 19:54:21 字数 3470 浏览 2 评论 0原文

在子组件中,我有一个具有以下结构的 XML 元素:

<position>
    <startOffset>*NUMBER*</startOffset>
    <numDays>*NUMBER*</numDays>
    <role>*String*</role>
    <student>*String*</student>
    <conflict>*BOOLEAN*</conflict>
</position>

然后,我使用转发器将每个元素列出到屏幕上。我创建了一个用于创建职位的按钮。因此,一旦用户单击此按钮,我就会调用以下函数:

private function addPosition(index:Number):void
{
    var tempObject:XML = XML("<position><startOffset>0</startOffset><numDays>3</numDays><role>1C</role><student> </student><conflict>false</conflict></position>");             
    projectPositions.appendChild(tempObject);
    projectHeight += 35;
    parentApplication.checkOverlap();           
}

上面的函数创建一个新的 XML 对象,放入一些默认值,并将其附加到项目位置列表中。附加新信​​息后,我增大了项目的高度,然后检查以确保新项目高度不与任何其他项目重叠......但该信息与本文无关。

我的问题是这样的 - 一旦我将一个新的子项附加到 XML 变量,它就不会出现在屏幕上。我可以对中继器执行“刷新”或“重新渲染”选项以使新的子项显示吗?

编辑 - 附加信息

这是变量声明(信息来自父级):

[Bindable] public var projectPositions:XML;

这是中继器(实际上调用另一个子级):

<mx:Repeater id="indPositions" dataProvider="{projectPositions.children()}" startingIndex="0">
    <components:block height="38" alpha=".75" 
        id="thisBlock" visible="true" horizontalScrollPolicy="off"
        width="{projectWidth}"
        oneDay="{Number(oneDay)}"
        position="{indPositions.currentItem.role}"
        offSet="{indPositions.currentItem.startOffset}"
        numDays="{indPositions.currentItem.numDays}"
        sName="{indPositions.currentItem.student}"
        isConflict="{indPositions.currentItem.conflict}"
        projectName="{projectTitle}"
        totalSpan="{returnSpan()}"
        projectsHttp="{projectsHttp}"
        allStudents="{allStudents}"
        thisBlockID="{indPositions.currentIndex}"
    />
</mx:Repeater>

然后,一旦用户单击“添加位置”按钮,调用以下函数:

private function addPosition(index:Number):void
{
    var tempObject:XML = XML("<position><startOffset>0</startOffset><numDays>3</numDays><role>" + possiblePositions[index] + "</role><student> </student><conflict>false</conflict></position>");
    positionsList.addItem(tempObject);
    projectHeight += 35;
    parentApplication.checkOverlap();
}

这就是我首先尝试做的事情(当我发表这篇文章时)...然后我在您的回复后更改了一些内容并最终得到以下结果:

声明:

[Bindable] public var projectPositions:XML;
[Bindable] public var projectXMLList:XMLList = XMLList(projectPositions);
[Bindable] public var projectPositionsXLC:XMLListCollection = XMLListCollection(projectXMLList);

中继器:

<mx:Repeater id="indPositions" dataProvider="{projectPositionsXLC}" startingIndex="0">

addPosition 功能:

private function addPosition(index:Number):void
{
    var tempObject:XML = XML("<position><startOffset>0</startOffset><numDays>3</numDays><role>" + possiblePositions[index] + "</role><student> </student><conflict>false</conflict></position>");               
    projectPositionsXLC.addItem(tempObject);
    projectHeight += 35;
    parentApplication.checkOverlap();           
}

一旦我做出更改,并使用 XMLListCollection作为转发器中的数据提供者,信息不再加载在屏幕上:(

Within a child, I have an XML element with the following structure:

<position>
    <startOffset>*NUMBER*</startOffset>
    <numDays>*NUMBER*</numDays>
    <role>*String*</role>
    <student>*String*</student>
    <conflict>*BOOLEAN*</conflict>
</position>

I then use a repeater to list each out onto the screen. There's a button I have created that is used to create a position. So, once the user clicks this button, I call the following function:

private function addPosition(index:Number):void
{
    var tempObject:XML = XML("<position><startOffset>0</startOffset><numDays>3</numDays><role>1C</role><student> </student><conflict>false</conflict></position>");             
    projectPositions.appendChild(tempObject);
    projectHeight += 35;
    parentApplication.checkOverlap();           
}

The above function creates a new XML object, puts some default values in, and appends it to the list of project positions. After appending the new information, I made the height of the project larger and then check to make sure the new project height isn't overlapping any other projects... but that information is irrelevant to this post.

My problem is this - once i append a new child to the XML variable, it doesn't appear on the screen. Is there a "refresh" or "re-render" option i can do to the repeater in order to make the new child show?

EDIT - additional information

Here's the variable declaration (information is coming from the parent):

[Bindable] public var projectPositions:XML;

Here's the repeater (which actually calls another child):

<mx:Repeater id="indPositions" dataProvider="{projectPositions.children()}" startingIndex="0">
    <components:block height="38" alpha=".75" 
        id="thisBlock" visible="true" horizontalScrollPolicy="off"
        width="{projectWidth}"
        oneDay="{Number(oneDay)}"
        position="{indPositions.currentItem.role}"
        offSet="{indPositions.currentItem.startOffset}"
        numDays="{indPositions.currentItem.numDays}"
        sName="{indPositions.currentItem.student}"
        isConflict="{indPositions.currentItem.conflict}"
        projectName="{projectTitle}"
        totalSpan="{returnSpan()}"
        projectsHttp="{projectsHttp}"
        allStudents="{allStudents}"
        thisBlockID="{indPositions.currentIndex}"
    />
</mx:Repeater>

Then, once the user clicks on the "Add position" button, the following function is called:

private function addPosition(index:Number):void
{
    var tempObject:XML = XML("<position><startOffset>0</startOffset><numDays>3</numDays><role>" + possiblePositions[index] + "</role><student> </student><conflict>false</conflict></position>");
    positionsList.addItem(tempObject);
    projectHeight += 35;
    parentApplication.checkOverlap();
}

That is what I tried doing first (when i made this post)... then i changed some stuff up after your responses and ended up with this:

Declarations:

[Bindable] public var projectPositions:XML;
[Bindable] public var projectXMLList:XMLList = XMLList(projectPositions);
[Bindable] public var projectPositionsXLC:XMLListCollection = XMLListCollection(projectXMLList);

Repeater:

<mx:Repeater id="indPositions" dataProvider="{projectPositionsXLC}" startingIndex="0">

addPosition Function:

private function addPosition(index:Number):void
{
    var tempObject:XML = XML("<position><startOffset>0</startOffset><numDays>3</numDays><role>" + possiblePositions[index] + "</role><student> </student><conflict>false</conflict></position>");               
    projectPositionsXLC.addItem(tempObject);
    projectHeight += 35;
    parentApplication.checkOverlap();           
}

Once i make the changes, and use the XMLListCollection as the dataprovider in the repeater, the information no longer loads on the screen :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2024-11-16 19:54:21

XMLList 不能成为处理列表更改的数据绑定的有效源。要摆脱正确的数据绑定,请使用 <改为代码>XMLListCollection

Pure XMLList can't be a valid source of data binding handling list changes. To have rid of proper data binding use XMLListCollection instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文