Flex 树不重新扩展

发布于 2024-08-20 10:28:39 字数 658 浏览 4 评论 0原文

我有一个树控件,在我将一个项目放入其中(更新数据提供程序)后,我希望它保持打开状态。我尝试了很多事情,包括 这个问题的示例 我无法上班,所以我正在做一些我觉得更基本的事情。像这样:

[Bindable]
public var open:Object = new Object();

private function dropItemInTree():void{
    open = myTree.openItems;
    //A bunch of code that updates the DP
    reopenTree();
}

public function reopenTree():void{
    for each(var item:XML in open){
        expandParents(item[0]);
    }
}

private function expandParents(node:XML):void {
    myTree.expandItem(node,true,false);
}

但即使这样,我的树也被最小化了。出了什么问题?

I have a tree control and after I drop an item in it (which updates the dataprovider) I want it to stay open. I've tried a lot of things including the example at this question which I couldn't get to work so I'm doing something I feel is even more basic. Like this:

[Bindable]
public var open:Object = new Object();

private function dropItemInTree():void{
    open = myTree.openItems;
    //A bunch of code that updates the DP
    reopenTree();
}

public function reopenTree():void{
    for each(var item:XML in open){
        expandParents(item[0]);
    }
}

private function expandParents(node:XML):void {
    myTree.expandItem(node,true,false);
}

But even this is leaving my tree minimized. What's going wrong?

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

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

发布评论

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

评论(2

终难遇 2024-08-27 10:28:39

所以我终于明白发生了什么事。在我的 drop 函数中,我基本上重建了整个 DP。虽然几乎相同,但在 Flash 播放器内会有不同的 UID,因此 open var 中的对象不再引用 DP 中的对象。幸运的是,我的 XML 数据提供程序中有一个 ID 字段,因此我可以使用该字段在重建的 DP 中查找该对象,并最终让 ExpandItem 方法在那里工作。

所以我的重新打开函数现在看起来像这样:

public function renderTree():void
    for each(var item:XML in open){
        myTree.expandItem(XML(MyDP..node.(@attr == item.@attr)),true);
        //forcing the type to be XML is VITAL
    }
}

So I finally figured out what was happening. In my drop function I was basically rebuilding the entire DP. While it was almost the same it would have had different UID's inside the flash player, so the objects in the open var no longer had reference the objects in the DP. Luckily there is an ID field in my XML dataprovider so using that I was able to look up the object in the rebuilt DP and finally get the expandItem method to work there.

So my re-open function now looks kind of like this:

public function renderTree():void
    for each(var item:XML in open){
        myTree.expandItem(XML(MyDP..node.(@attr == item.@attr)),true);
        //forcing the type to be XML is VITAL
    }
}
三岁铭 2024-08-27 10:28:39

抱歉,这是完整的解释:底部的链接提供了完整的解释以及完整的示例。

您必须使用 Tree 控件的creationComplete 事件,而不是initialize 事件,因为数据提供程序在creationComplete 事件之前尚未完全初始化且可用。

<mx:Tree id="tree1" ... creationComplete="initTree();" >

或者,

您还可以通过设置 ExpandItem() 方法来调度 itemOpen 事件,让 openItems 框指示初始打开的项目。您可以通过将 ExpandItem() 方法的第四个可选参数指定为 true 来实现此目的。 true 第四个参数使树在项目打开时调度打开事件。以下示例显示了第四个参数的用法:

XMLTree1.expandItem(MailBox.getItemAt(0), true, false, true);

默认情况下,Tree 控件在初始化时会折叠,但您可以对其进行初始化,使其展开并选择特定的节点。

<mx:Script>
    <![CDATA[
        import flash.events.*;
        import mx.events.*;
        import mx.controls.*;
        private function initTree():void {

            XMLTree1.expandItem(MailBox.getItemAt(0), true);
            XMLTree1.selectedIndex = 2;
        }
    ]]>
</mx:Script>

树控件的参考是: http:// livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_8.html

Sorry, here is the full explanation: The link at the bottom gives the complete explanation along with a full sample.

You must use the Tree control's creationComplete event, not the initialize event, because the data provider is not fully initialized and available until the creationComplete event.

<mx:Tree id="tree1" ... creationComplete="initTree();" >

OR

you could also get the openItems box to indicate the initial open item by setting the expandItem() method to dispatch an itemOpen event. You can do this by specifying the fourth, optional parameter of the expandItem() method to true. The true fourth parameter causes the tree to dispatch an open event when the item opens. The following example shows the use of the fourth parameter:

XMLTree1.expandItem(MailBox.getItemAt(0), true, false, true);

By default, a Tree control is collapsed when it initializes, but you can initialize it so that it is expanded with a specific node selected.

<mx:Script>
    <![CDATA[
        import flash.events.*;
        import mx.events.*;
        import mx.controls.*;
        private function initTree():void {

            XMLTree1.expandItem(MailBox.getItemAt(0), true);
            XMLTree1.selectedIndex = 2;
        }
    ]]>
</mx:Script>

The reference for the tree control is: http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_8.html

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