ItemRender 数据更改
我有一个带有 ItemRenderer 的列表。当我单击按钮时,绑定到列表的 ArrayCollection 的属性就会更改。
当我单击该按钮时,它确实会更改属性,但列表不会更改。
我该如何解决这个问题。
这是我的代码
<fx:Script>
<![CDATA[
[Bindable]
public var controllers:ControllerCollection = new ControllerCollection();
private function hideTheFirstItem(evt:MouseEvent):void
{
(controllers[0] as Controller).meetsRequirements = false;
//these methods don't work unfortunatly
controllers.itemUpdated(controllers[0]);
controllers.refresh();
}
]]>
</fx:Script>
<mx:List id="listControllers" dataProvider="{controllers}">
<mx:itemRenderer>
<fx:Component>
<solutionItems:displaySolutionItem visible="{data.meetsRequirements}" />
</fx:Component>
</mx:itemRenderer>
</mx:List>
<mx:Button label="test" click="hideTheFirstItem(event)" />
(ControllerCollection 扩展了 ArrayCollection)
谢谢!
文森特
I have a List with an ItemRenderer. When I click a button, then a property of the ArrayCollection I bound to the list is changed.
When I click the button, then it does change the property, but the list doesn't change.
How do I solve this.
Here's my code
<fx:Script>
<![CDATA[
[Bindable]
public var controllers:ControllerCollection = new ControllerCollection();
private function hideTheFirstItem(evt:MouseEvent):void
{
(controllers[0] as Controller).meetsRequirements = false;
//these methods don't work unfortunatly
controllers.itemUpdated(controllers[0]);
controllers.refresh();
}
]]>
</fx:Script>
<mx:List id="listControllers" dataProvider="{controllers}">
<mx:itemRenderer>
<fx:Component>
<solutionItems:displaySolutionItem visible="{data.meetsRequirements}" />
</fx:Component>
</mx:itemRenderer>
</mx:List>
<mx:Button label="test" click="hideTheFirstItem(event)" />
(ControllerCollection extends ArrayCollection)
Thanks!
Vincent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
两种方式:
当然,ControllerCollection 不是一个标准的 Flex Collection 类;所以我只是假设它实现了 ICollectionView 接口。
更新:
我确实注意到您的代码设置为修改 ArrayCollection 的第一个元素,
我想确保指定集合的第一个元素可能不是视图中当前可见的第一个元素。我想知道这是否给你带来了问题。
Two ways:
Of course, ControllerCollection is not a standard Flex Collection class; so I am just assuming that it implements the ICollectionView interface.
Update:
I do notice that your code is set to modify the first element of the ArrayCollection
I wanted to be sure to specify that the first element of the collection may not be the first element currently visible in the view. I wonder if that is causing you issues.
在没有看到您的项目渲染器的情况下,我需要做出一些假设。
首先,我假设您的项目渲染器使用数据绑定到
meetsRequirements
属性。如果是这种情况,则meetsRequirements
属性需要在该属性发生更改时发出通知。如果将[Bindable]
标记添加到该属性或Controller
类,则meetsRequirements
属性将通知 itemRenderer 根据该字段更新该字段关于您的数据绑定。如果我的假设是错误的,我们需要查看代码以便为您提供进一步的想法。
Without seeing your item renderer, I need to make some assumptions.
First, I will assume that your item renderer is using data binding to the
meetsRequirements
property. If that is the case, then themeetsRequirements
property needs to notify when that property changes. If you add the[Bindable]
tag to that property or theController
class, then themeetsRequirements
property will notify the itemRenderer to update that field based on your data binding.If my assumptions are wrong, we need to see the code to give you any further thoughts.
首先,如果不需要,请不要尝试创建新集合。
我相信您的问题在于以下语句:
(controllers[0] as Controller).meetsRequirements = false;
编译时应该失败,因为无法使用方括号注释检索集合项。您需要使用 getItemAt(index:int) 函数。此外,如果您想“删除”项目渲染器,您不会希望将其可见设置为 false,因为这样您就会有一个空位。你想要做的就是将其过滤掉:
这应该可以做到。虽然未经测试。
First, don't try to create new collections if you don't need to.
I believe your problem lies with this statement:
(controllers[0] as Controller).meetsRequirements = false;
which should fail on compile because a collection item cannot be retrieved using the square bracket annotation. You need to usegetItemAt(index:int)
function.Furthermore, you wouldn't want to set visible to false to an item renderer if you want to 'remove' it because then you'd have an empty spot. What you want to do is filter it out:
This should do it. Untested though.
试试这个:
Try this: