为什么更新 HierarchicalData dataProvider 时 AdvancedDataGrid 不更新?
我有一个带有 HierarchicalData dataProvider 的 AdvancedDataGrid (ADG):
<mx:AdvancedDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
dataProvider="{__model.myHierarchicalData}"
displayItemsExpanded="true" sortExpertMode="true" dropEnabled="true"
sortableColumns="false" draggableColumns="false"
resizableColumns="true" textAlign="left" defaultLeafIcon="{null}"
folderOpenIcon="{null}" folderClosedIcon="{null}"/>
当我最初在模型中设置 HierarchicalData 实例时,它按预期显示:
function buildHierarchicalData(parentItems:ArrayCollection):void
{
__model.myHierarchicalData = new HierarchicalData();
__model.myHierarchicalData.source = parentItems;
}
parentItems 是 ParentItem valueObjects 的集合:
package
{
[Bindable]
public class ParentItem
{
public var children:ArrayCollection;
public var label:String;
}
}
但是,当我移动子项时项目从一个父级到另一个父级(通过拖放),使用以下代码更新不可见:
function moveChildren(movedChildren:Array /* of ParentItem */):void
{
parentItem.children = new ArrayCollection(movedChildren);
}
但是,出于某种原因,这确实有效:
function moveChildren(movedChildren:Array /* of ParentItem */):void
{
parentItem.children.source = movedChildren;
}
为什么我必须更新 ArrayCollection 的源???
I have an AdvancedDataGrid (ADG) with a HierarchicalData dataProvider:
<mx:AdvancedDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
dataProvider="{__model.myHierarchicalData}"
displayItemsExpanded="true" sortExpertMode="true" dropEnabled="true"
sortableColumns="false" draggableColumns="false"
resizableColumns="true" textAlign="left" defaultLeafIcon="{null}"
folderOpenIcon="{null}" folderClosedIcon="{null}"/>
When I initially set the HierarchicalData instance in the Model, it is displayed as expected:
function buildHierarchicalData(parentItems:ArrayCollection):void
{
__model.myHierarchicalData = new HierarchicalData();
__model.myHierarchicalData.source = parentItems;
}
parentItems is a Collection of ParentItem valueObjects:
package
{
[Bindable]
public class ParentItem
{
public var children:ArrayCollection;
public var label:String;
}
}
However, when I move child items from one parent to another (via drag-and-drop), the update is not visible, using this code:
function moveChildren(movedChildren:Array /* of ParentItem */):void
{
parentItem.children = new ArrayCollection(movedChildren);
}
For some reason, however, this DOES work:
function moveChildren(movedChildren:Array /* of ParentItem */):void
{
parentItem.children.source = movedChildren;
}
Why do I have to update the source of the ArrayCollection???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢 dirkgently 指导我找到答案。 我现在不再需要模型中的 HierarchicalData 属性,而是在 MXML 中设置 Hierarchical dataProvider:
Thanks to dirkgently for directing me to the answer. I am now eliminating the need for a HierarchicalData property in my model, and instead setting the Hierarchical dataProvider right in the MXML:
请参阅此内容。 建议在处理
dataProviders
时始终使用可绑定的ArrayCollection
。See this. It is recommended to use a bindable
ArrayCollection
always when dealing withdataProviders
.尝试
Try