简体   繁体   English

Flex数据绑定对象转换为ArrayCollection

[英]Flex data binding object converted to ArrayCollection

I have a somewhat complex parent/child hierarchy object that I need to display in a tree format that dynamically updates. 我有一个稍微复杂的父/子层次结构对象,需要以动态更新的树格式显示。 To pass it into the tree as a dataprovider I convert the top level parent into an Array and then into an ArrayCollection. 要将其作为数据提供者传递到树中,我将顶级父级转换为Array,然后转换为ArrayCollection。 The problem there is if anything changes in the hierarchy the tree isn't dynamically updated unless I regenerate the dataprovider. 问题是,如果层次结构中没有任何更改,除非重新生成dataprovider,否则不会动态更新树。

EDIT: I didn't have much code shown so I just tried to include the skeleton version of how everything is being used below, the tree works fine and even when I remove/add nodes the changes are evident but the vertical scroll bar isn't updated(doesn't resize) and if I scroll the tree will get out of whack and may display whitespace at the bottom of the tree where the item was just removed. 编辑:我没有显示太多代码,所以我只是尝试在下面包括所有用法的框架版本,树正常工作,即使当我删除/添加节点时,变化也很明显,但垂直滚动条却没有。 t更新(不调整大小),如果我滚动,树将摆脱束缚,并可能在刚刚删除该项目的树底部显示空白。

I tried just a plain bindable ArrayCollection test object with multiple levels and it updates properly so I think my tree is fine it's just how I'm trying to bind the dataprovider that I'm having the issues. 我只是尝试了一个具有多个级别的普通可绑定ArrayCollection测试对象,它可以正确更新,所以我认为我的树还不错,这就是我试图绑定遇到问题的dataprovider的方式。

AS3 Class 1 - Object that can have plenty of child objects of itself by calling insertCustomObject() AS3第1类-通过调用insertCustomObject()可以具有大量子对象的对象

public function CustomObject() {

}
public function insertCustomObject(customObject : CustomObject) : void {
    customObject.parent = this;
}

AS3 Class 2 - contains a single CustomObject that will have a plenty of children which is what I want displayed as the tree. AS3第2类-包含一个CustomObject,它将有很多子代,这就是我要显示为树的子代。

public class CustomContainer {
    private var _root : CustomObject;

    public function rootAsCollection() : ArrayCollection {
        return new ArrayCollection(new Array(_root));
    }
}

MXML Component 1 - Contains the custom tree component and passed it customObjects to be used as the dataprovider MXML组件1-包含自定义树组件,并将其传递给customObjects用作数据提供者

[Bindable]
private var customContainer : CustomContainer;

<component:TreeCustom id="treeCustom" width="100%" customObjects="{customContainer.rootAsCollection()}"/>

MXML Component 2 - The tree itself, takes in the customObjects parameter from MXML Component 1 to set it's dataprovider. MXML组件2-树本身从MXML组件1接受customObjects参数以设置其数据提供程序。

[Bindable]
private var _customObjects : ArrayCollection;

public function set customObjects(objects : ArrayCollection) : void {
    _customObjects = objects;
}

<mx:Tree id="customTree" dataProvider="{_customObjects}" />

You should use ArrayCollection instead of array when you are providing list of child items in tree. 当您在树中提供子项列表时,应使用ArrayCollection而不是array。 Array does not dispatch change events when element is added or removed and Tree can not update accordingly. 当添加或删除元素并且Tree无法相应更新时, Array不会调度更改事件。

Here is an example of class that can be user to compose data hierarchy: 这是可以作为用户组成数据层次结构的类的示例:

public class Person extends EventDispatched
{

    public function Person(name:String, children:ArrayCollection)
    {
        super();

        this.name = name;
        this.children = children;
    }

    [Bindable]
    public var name:String;

    [Bindable]
    public var children:ArrayCollection;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ArrayCollection的数据用于Flex中的标签测试? - ArrayCollection of data for label test in flex? Flex ArrayCollection-访问对象方法/属性? - Flex ArrayCollection - accesing object methods / attributes? 在Flex中基于arraycollection数据过滤datagrid - Filter datagrid based on arraycollection data in flex Flex-使用arrayCollection用来自JavaScript的数据填充Combobox - Flex - populate Combobox with arrayCollection with data from javascript Flex中用于图像和图标的fx:object的数据绑定 - Data binding of an fx:object in flex for image and icon 柔性。 pushView数据对象正在转换为字符串 - Flex. pushView data Object being converted into a String Flex:另一个ArrayCollection中有arrayCollection吗? - Flex: arrayCollection inside another ArrayCollection? Flex Mobile动作脚本如何按对象的一部分按字母顺序对arrayCollection进行排序 - Flex Mobile actionscript how to alphabetically sort a arrayCollection by a portion of a object 可能让Flex将自定义ArrayCollection用于来自服务器的远程对象? - Possible to get Flex to use custom ArrayCollection for remote object from server? 挑战:如何有效地填补稀疏的Flex ArrayCollection中的数据空白? - Challenge: How to efficiently fill data gaps in an sparse Flex ArrayCollection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM