Flex 4 Mx:tree 未使用 tree.refresh() 或 tree.reset() 更新

Flex 4 Mx:tree not updating with tree.refresh() or tree.reset()

我正在使用 Flex 4 创建一个 mx:tree 并且树中正在填充一个 XMLList 文件,该文件是从数据库更新的,我想要完成的是刷新树,以便根据课程的完成状态显示不同的图标。

问题是树没有更新,但是 XMLList 文件更新了,所以非常感谢您的帮助。

顺便说一句,我不知道 Flex。

代码如下:

public static var treeData:XMLList = new XMLList(MyString);

<mx:Tree id="myTree" width="40%" height="100%" labelField="@label" fontSize="14" focusColor="#ff5003"
                     render="renderTree()"
                     iconFunction="tree_iconFunc"
                     showRoot="false"
                     dataProvider="{treeData}"  
                         change="treeChanged(event)" 
                         depthColors="{myDepthColors}"
                         color="#006596" borderColor="#03B4EC"
                         click="SoundExample(String(selectedNode.@lesson)), habilitar()"
                         alternatingItemColors="{myAlternatingRowColors}"

                         />



    public function renderTree():void {
                    trace("Entró a renderTree");
                    initAppB();
                    if (refreshData){

                        myTree.invalidateList();
                        refreshData = false;
                        myTree.openItems = Globals.treeData;

                        myTree.validateNow();
                    }
                }

相反 XMLList 您可以使用 可绑定 集合,例如 ArrayCollection。 有了它,您不需要手动使树无效。当ArrayCollection变化时会自动更新。

此外,我不确定 "the tree is being populated with an XMLList file, the file is updated from a database" 是什么意思。你能澄清一下吗?

要更新树,您必须更新 treeData:XMLList。如果您想将其替换为另一个值,请尝试以下操作:

[Bindable] //Notice this metadata
public var treeData:XMLList = new XMLList(MyString);
public function updateTreeData():void {
    var text:String = ...; //loading text
    treeData = new XMLList(text);
}